diff --git a/Box42.xcodeproj/project.pbxproj b/Box42.xcodeproj/project.pbxproj index 229e011..a75f858 100644 --- a/Box42.xcodeproj/project.pbxproj +++ b/Box42.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + D65C5C7C2AA195AB00BD291A /* prefsHelper.app in Resources */ = {isa = PBXBuildFile; fileRef = D65C5C7B2AA195AB00BD291A /* prefsHelper.app */; }; DE018BB32A5099F900FF0AA3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE018BB22A5099F900FF0AA3 /* AppDelegate.swift */; }; DE018BB82A5099F900FF0AA3 /* Box42.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = DE018BB62A5099F900FF0AA3 /* Box42.xcdatamodeld */; }; DE018BDD2A509AEB00FF0AA3 /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE018BDC2A509AEB00FF0AA3 /* EventMonitor.swift */; }; @@ -124,6 +125,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + D65C5C7B2AA195AB00BD291A /* prefsHelper.app */ = {isa = PBXFileReference; lastKnownFileType = wrapper.application; name = prefsHelper.app; path = ../../Downloads/prefsHelper.app; sourceTree = ""; }; DE018BAF2A5099F900FF0AA3 /* Box42.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Box42.app; sourceTree = BUILT_PRODUCTS_DIR; }; DE018BB22A5099F900FF0AA3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; DE018BB72A5099F900FF0AA3 /* Box42.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Box42.xcdatamodel; sourceTree = ""; }; @@ -258,6 +260,7 @@ DE018BA62A5099F900FF0AA3 = { isa = PBXGroup; children = ( + D65C5C7B2AA195AB00BD291A /* prefsHelper.app */, DE018BB12A5099F900FF0AA3 /* Box42 */, DE018BB02A5099F900FF0AA3 /* Products */, DE17AF722A834A1600325BF4 /* Frameworks */, @@ -825,6 +828,7 @@ DE7F9D462A9B7A4700F8ACAE /* QuickSlotButtonViewItem.xib in Resources */, DEB862D92A852C4500278FCD /* brewInGoinfre.sh in Resources */, DE62BE5A2A9BA31700D97E06 /* QuickSlotButtonCollectionViewController.xib in Resources */, + D65C5C7C2AA195AB00BD291A /* prefsHelper.app in Resources */, DE018BE02A509B0600FF0AA3 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Box42.xcodeproj/project.xcworkspace/xcuserdata/daskim.xcuserdatad/UserInterfaceState.xcuserstate b/Box42.xcodeproj/project.xcworkspace/xcuserdata/daskim.xcuserdatad/UserInterfaceState.xcuserstate index 8f50922..d3fbbb4 100644 Binary files a/Box42.xcodeproj/project.xcworkspace/xcuserdata/daskim.xcuserdatad/UserInterfaceState.xcuserstate and b/Box42.xcodeproj/project.xcworkspace/xcuserdata/daskim.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Box42/QuickSlot/View/QuickSlotGroupView.swift b/Box42/QuickSlot/View/QuickSlotGroupView.swift index 228c26b..b6789f5 100644 --- a/Box42/QuickSlot/View/QuickSlotGroupView.swift +++ b/Box42/QuickSlot/View/QuickSlotGroupView.swift @@ -11,7 +11,7 @@ import SnapKit class QuickSlotGroupView: NSView { lazy var divider: NSBox = Divider(completion: { [weak self] in self?.dividerAction?() }) - lazy var headerView: QuickSlotHeaderView = QuickSlotHeaderView(image: NSImage(imageLiteralResourceName: "star"), completion: { [weak self] in self?.headerAction?() }) + lazy var headerView: QuickSlotHeaderView = QuickSlotHeaderView(image: NSImage(imageLiteralResourceName: "Star"), completion: { [weak self] in self?.headerAction?() }) lazy var buttonCollectionView: QuickSlotButtonCollectionViewController = QuickSlotButtonCollectionViewController() var dividerAction: (() -> Void)? diff --git a/Box42/Resources/Info.plist b/Box42/Resources/Info.plist index 4187051..e470c4d 100644 --- a/Box42/Resources/Info.plist +++ b/Box42/Resources/Info.plist @@ -2,8 +2,8 @@ - NSAppleEventsUsageDescription - This app needs access to control System Preferences. + NSAppleEventsUsageDescription + This app needs access to control System Preferences. NSDocumentsFolderUsageDescription 원활한 앱 구동을 위해 유저 디렉토리의 권한을 요청합니다. NSAppTransportSecurity diff --git a/Box42/Toolbar/Controller/ToolbarViewController.swift b/Box42/Toolbar/Controller/ToolbarViewController.swift index c5df281..45d74e0 100644 --- a/Box42/Toolbar/Controller/ToolbarViewController.swift +++ b/Box42/Toolbar/Controller/ToolbarViewController.swift @@ -25,6 +25,19 @@ class ToolbarViewController: NSViewController { // Do view setup here. } +// func runPrefsHelperApplication() { +// let prefsHelperAppPath = "/Users/daskim/Downloads/prefsHelper.app" // prefsHelper.app의 경로 +// +// let appURL = URL(fileURLWithPath: prefsHelperAppPath) +// +// let workspace = NSWorkspace.shared +// do { +// try workspace.open([appURL], withAppBundleIdentifier: nil, options: [], additionalEventParamDescriptor: nil, launchIdentifiers: nil) +// } catch { +// print("Error opening app: \(error)") +// } +// } + func sidebar() { print("sidebar") } diff --git a/Box42/Toolbar/View/SideBarLeading.swift b/Box42/Toolbar/View/SideBarLeading.swift index 24c2f1c..c177e12 100644 --- a/Box42/Toolbar/View/SideBarLeading.swift +++ b/Box42/Toolbar/View/SideBarLeading.swift @@ -29,7 +29,41 @@ class SideBarLeading: NSButton { fatalError("init(coder:) has not been implemented") } + func runScript() { + let scriptSource = """ + tell application "System Preferences" + activate + end tell + """ + + if let appleScript = NSAppleScript(source: scriptSource) { + var errorDict: NSDictionary? = nil + appleScript.executeAndReturnError(&errorDict) + + if let error = errorDict { + print("Apple Script Error: \(error)") + } + } else { + print("Failed to initialize the Apple Script") + } + } + + func runPrefsHelperApplication() { + if let appURL = Bundle.main.url(forResource: "prefsHelper", withExtension: "app") { + let workspace = NSWorkspace.shared + do { + try workspace.open([appURL], withAppBundleIdentifier: nil, options: [], additionalEventParamDescriptor: nil, launchIdentifiers: nil) + } catch { + print("Error opening app: \(error)") + } + } else { + print("App not found") + } + } + + @objc func sideBarLeading() { + runPrefsHelperApplication() callback?() } } diff --git a/Box42/View/BoxContentsViewGroup.swift b/Box42/View/BoxContentsViewGroup.swift index 959fb80..bb48f46 100644 --- a/Box42/View/BoxContentsViewGroup.swift +++ b/Box42/View/BoxContentsViewGroup.swift @@ -8,22 +8,105 @@ import WebKit import SnapKit -class BoxContentsViewGroup: NSView { - var webVC: WebViewController? +class BoxContentsViewGroup: NSView, WKUIDelegate { + // var webVC: WebViewController? var preferencesVC = PreferencesViewController() var scriptsVC = ScriptsViewController() + + var webView: WKWebView! + static let shared = BoxContentsViewGroup() init() { super.init(frame: .zero) - webVC = WebViewController(nibName: nil, bundle: nil) + // webVC = WebViewController(nibName: nil, bundle: nil) self.wantsLayer = true self.layer?.cornerRadius = 20 self.layer?.masksToBounds = true - self.addSubview(webVC!.view) - webVC?.view.snp.makeConstraints { make in + + // self.addSubview(webVC!.view) + // webVC?.view.snp.makeConstraints { make in + // make.edges.equalTo(self) + // } + + let webConfiguration = WKWebViewConfiguration() + webView = WKWebView(frame: .zero, configuration: webConfiguration) + webView.uiDelegate = self + WebViewManager.shared.hostingWebView = webView + self.addSubview(webView) + webView.snp.makeConstraints { make in make.edges.equalTo(self) } + + if let url = URL(string: "https://www.42box.kr") { + let request = URLRequest(url: url) + webView.load(request) + } + + NotificationCenter.default.addObserver(self, selector: + #selector(goBack), name: + Notification.Name("goBack"), object:nil) + + NotificationCenter.default.addObserver(self, selector: + #selector(goForward), name: + Notification.Name("goForward"), object:nil) + + NotificationCenter.default.addObserver(self, selector: + #selector(reload), name: + Notification.Name("reload"), object:nil) + } + + deinit { + // view controller가 해제될 때 observer도 제거합니다. + NotificationCenter.default.removeObserver(self) + } + + @objc func goBack() { + if webView.canGoBack { + webView.goBack() + } } + + @objc func goForward() { + if webView.canGoForward { + webView.goForward() + } + } + + @objc func reload() { + webView.reload() + } + + func webView(_ webView: WKWebView, + createWebViewWith configuration: WKWebViewConfiguration, + for navigationAction: WKNavigationAction, + windowFeatures: WKWindowFeatures) -> WKWebView? { + + if navigationAction.targetFrame == nil { + if let url = navigationAction.request.url { + if navigationAction.navigationType == .linkActivated { + webView.load(URLRequest(url: url)) + return nil + } + } + } + return nil + } + + func webView(_ webView: WKWebView, runOpenPanelWith parameters: WKOpenPanelParameters, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping ([URL]?) -> Void) { + let openPanel = NSOpenPanel() + openPanel.canChooseFiles = true + openPanel.allowsMultipleSelection = parameters.allowsMultipleSelection + openPanel.level = .popUpMenu + + openPanel.begin { (result) in + if result == .OK { + completionHandler(openPanel.urls) + } else { + completionHandler(nil) + } + } + } + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented")