diff --git a/Box42.xcodeproj/project.pbxproj b/Box42.xcodeproj/project.pbxproj index 6e15b5e..3f287e1 100644 --- a/Box42.xcodeproj/project.pbxproj +++ b/Box42.xcodeproj/project.pbxproj @@ -532,8 +532,7 @@ DE2AD3282A824EEB00002D51 /* Accessibility.swift */, DE874F4D2A591DEA00FC3B77 /* Hotkey.swift */, ); - name = Preferences; - path = QuickSlot/Preferences; + path = Preferences; sourceTree = ""; }; DE9456F62A9E44F100B0B768 /* Icon */ = { diff --git a/Box42/QuickSlot/Preferences/Accessibility.swift b/Box42/Preferences/Accessibility.swift similarity index 100% rename from Box42/QuickSlot/Preferences/Accessibility.swift rename to Box42/Preferences/Accessibility.swift diff --git a/Box42/QuickSlot/Preferences/Controller/PreferencesViewController.swift b/Box42/Preferences/Controller/PreferencesViewController.swift similarity index 100% rename from Box42/QuickSlot/Preferences/Controller/PreferencesViewController.swift rename to Box42/Preferences/Controller/PreferencesViewController.swift diff --git a/Box42/QuickSlot/Preferences/Hotkey.swift b/Box42/Preferences/Hotkey.swift similarity index 100% rename from Box42/QuickSlot/Preferences/Hotkey.swift rename to Box42/Preferences/Hotkey.swift diff --git a/Box42/QuickSlot/Preferences/PreferencesView.swift b/Box42/Preferences/PreferencesView.swift similarity index 100% rename from Box42/QuickSlot/Preferences/PreferencesView.swift rename to Box42/Preferences/PreferencesView.swift diff --git a/Box42/Preferences/PreferencesViewController.swift b/Box42/Preferences/PreferencesViewController.swift deleted file mode 100644 index e132672..0000000 --- a/Box42/Preferences/PreferencesViewController.swift +++ /dev/null @@ -1,147 +0,0 @@ -// -// PreferencesViewController.swift -// Box42 -// -// Created by Chanhee Kim on 7/24/23. -// - -import Cocoa -import Foundation - -class PreferencesViewController: NSViewController { - let menubarVC = MenubarViewController() - private var stackView: NSStackView! - private var rightView: NSView! - private var outputView: NSTextView! - - override func loadView() { - self.view = NSView() - self.stackView = NSStackView() - self.stackView.orientation = .vertical - self.stackView.distribution = .fillEqually - self.stackView.spacing = 20 - self.view.addSubview(stackView) - stackView.translatesAutoresizingMaskIntoConstraints = false - NSLayoutConstraint.activate([ - stackView.topAnchor.constraint(equalTo: self.view.topAnchor), - stackView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor), - stackView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor), - stackView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor) - ]) - - let leftView = NSView() - self.rightView = NSView() - self.stackView.addArrangedSubview(leftView) - self.stackView.addArrangedSubview(rightView) - - outputView = NSTextView() - outputView.translatesAutoresizingMaskIntoConstraints = false - rightView.addSubview(outputView) - - NSLayoutConstraint.activate([ - outputView.topAnchor.constraint(equalTo: rightView.topAnchor), - outputView.leadingAnchor.constraint(equalTo: rightView.leadingAnchor), - outputView.trailingAnchor.constraint(equalTo: rightView.trailingAnchor), - outputView.bottomAnchor.constraint(equalTo: rightView.bottomAnchor) - ]) - - - var stackBox: [NSView] = [] - - - let scripts = Scripts().info - scripts.forEach { (script) in - stackBox.append(NSButton(title: "\(script.name) Script: \(script.description)", target: self, action: #selector(scriptButtonPressed))) - - } - -// let scriptButton = NSButton(title: "Script", target: self, action: #selector(scriptButtonPressed)) - let appleScriptButton = NSButton(title: "Apple Script", target: self, action: #selector(scriptButtonPressed)) - let etcButton = NSButton(title: "Etc.", target: self, action: #selector(etcButtonPressed)) - -// stackBox.append(scriptButton) - stackBox.append(appleScriptButton) - stackBox.append(etcButton) - let buttonStackView = NSStackView(views: stackBox) - buttonStackView.orientation = .vertical - buttonStackView.distribution = .fillEqually - buttonStackView.spacing = 20 - leftView.addSubview(buttonStackView) - buttonStackView.translatesAutoresizingMaskIntoConstraints = false - NSLayoutConstraint.activate([ - buttonStackView.topAnchor.constraint(equalTo: leftView.topAnchor), - buttonStackView.leadingAnchor.constraint(equalTo: leftView.leadingAnchor), - buttonStackView.trailingAnchor.constraint(equalTo: leftView.trailingAnchor), - buttonStackView.bottomAnchor.constraint(equalTo: leftView.bottomAnchor) - ]) - } - - @objc func changeIconButtonPressed(_ sender: NSButton) { - // Change the content of the right view for icon changing - let icon = sender.title.split(separator: " ").map{String($0)} - print(icon[1]) - menubarVC.menubarStopRunning() - menubarVC.buttonImageChange(icon[1]) - menubarVC.menubarStartRunning() - } - - @objc func scriptButtonPressed(_ sender: NSButton) { - let script = sender.title.split(separator: " ").map{String($0)} - if script[1] == "Script:" { - if let scriptPath = Bundle.main.path(forResource: script[0], ofType: "sh") { - let task = Process() - task.launchPath = "/bin/sh" - task.arguments = [scriptPath] - - let outputPipe = Pipe() - task.standardOutput = outputPipe - task.standardError = outputPipe - - - task.standardError = outputPipe - -// outputPipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in -// if #available(OSX 10.15.4, *) { -// if let data = try? fileHandle.readToEnd(), let output = String(data: data, encoding: .utf8) { -// DispatchQueue.main.async { -// if let outputView = self?.outputView { -// outputView.string += "\(output)" -// } else { -// print("outputView is nil") -// } -// } -// } -// } else { -// // Fallback on earlier versions -// } -// } - - - task.launch() - task.waitUntilExit() - -// let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile() -// let output = String(data: outputData, encoding: .utf8) ?? "" -// print("Output: \(output)") - } else { - print("Script not found") - } - } else if sender.title == "Apple Script" { - let appleScriptCode = "display dialog \"Hello, World!\"" - - if let appleScript = NSAppleScript(source: appleScriptCode) { - var errorDict: NSDictionary? = nil - appleScript.executeAndReturnError(&errorDict) - - if let error = errorDict { - print("Error: \(error)") - } - } - } - } - - @objc func etcButtonPressed() { - // Change the content of the right view for etc. - } -} - diff --git a/Box42/QuickSlot/Preferences/View/PreferencesCell.swift b/Box42/Preferences/View/PreferencesCell.swift similarity index 100% rename from Box42/QuickSlot/Preferences/View/PreferencesCell.swift rename to Box42/Preferences/View/PreferencesCell.swift diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..81101ad --- /dev/null +++ b/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "SnapKit", + "repositoryURL": "https://github.com/SnapKit/SnapKit", + "state": { + "branch": null, + "revision": "f222cbdf325885926566172f6f5f06af95473158", + "version": "5.6.0" + } + } + ] + }, + "version": 1 +}