From 71a5eb23d2facbb68255547ab662b17620709f57 Mon Sep 17 00:00:00 2001 From: AlvinZhu Date: Sat, 19 Dec 2020 21:28:23 +0800 Subject: [PATCH] fix #29 #34 #35 --- Thor/AppDelegate.swift | 16 +++++++++++++++ Thor/Base.lproj/Main.storyboard | 34 +++++++++++++++++++++---------- Thor/Constant.swift | 1 + Thor/SettingsViewController.swift | 9 ++++++++ Thor/Thor.entitlements | 7 ++++++- Thor/zh-Hans.lproj/Main.strings | 3 +++ 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/Thor/AppDelegate.swift b/Thor/AppDelegate.swift index 74a1ce5..655063e 100644 --- a/Thor/AppDelegate.swift +++ b/Thor/AppDelegate.swift @@ -44,6 +44,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { shortcutEnableMonitor() handleLaunchAtLogin() + registerMenubarIconShortcut() MASShortcutValidator.shared().allowAnyShortcutWithOptionModifier = true ShortcutMonitor.register() @@ -145,4 +146,19 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } + func registerMenubarIconShortcut() { + let shortcut = MASShortcut(keyCode: kVK_ANSI_T, modifierFlags: [.shift, .control, .option, .command]) + MASShortcutMonitor.shared().register(shortcut, withAction: { + defaults[.enableMenuBarIcon] = !defaults[.enableMenuBarIcon] + + if defaults[.enableMenuBarIcon] { + sharedAppDelegate?.statusItemController.showInMenuBar() + } else { + sharedAppDelegate?.statusItemController.hideInMenuBar() + } + + NotificationCenter.default.post(name: .updateMenuBarToggleState, object: nil) + }) + } + } diff --git a/Thor/Base.lproj/Main.storyboard b/Thor/Base.lproj/Main.storyboard index 438b418..73f110c 100644 --- a/Thor/Base.lproj/Main.storyboard +++ b/Thor/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -241,7 +241,7 @@ - + @@ -353,7 +353,7 @@ - + @@ -361,7 +361,7 @@ - + @@ -395,7 +395,7 @@ - + @@ -403,7 +403,7 @@ - + @@ -411,7 +411,7 @@ - + @@ -419,7 +419,7 @@ - + @@ -444,7 +444,7 @@ + + + + + + + + @@ -473,10 +481,10 @@ + - @@ -486,6 +494,7 @@ + @@ -493,12 +502,15 @@ + + + diff --git a/Thor/Constant.swift b/Thor/Constant.swift index 2aa2771..9e31f80 100644 --- a/Thor/Constant.swift +++ b/Thor/Constant.swift @@ -26,4 +26,5 @@ let windowbackgroundColorName = "WindowBackgroundColor" // Notifications extension Notification.Name { static let killLauncher = Notification.Name("killLauncher") + static let updateMenuBarToggleState = Notification.Name("updateMenuBarToggleState") } diff --git a/Thor/SettingsViewController.swift b/Thor/SettingsViewController.swift index 7f1a506..ca686ac 100644 --- a/Thor/SettingsViewController.swift +++ b/Thor/SettingsViewController.swift @@ -37,6 +37,11 @@ class SettingsViewController: NSViewController { slider.doubleValue = defaults[.DelayInterval] slider.isEnabled = isEnableDeactivateKey + + NotificationCenter.default.addObserver(self, + selector: #selector(updateMenuBarToggleState), + name: .updateMenuBarToggleState, + object: nil) } @IBAction func toggleLaunchAtLogin(_ sender: Any) { @@ -84,4 +89,8 @@ class SettingsViewController: NSViewController { NSApp.terminate(self) } + @objc func updateMenuBarToggleState() { + btnEnableMenuBarIcon.state = defaults[.enableMenuBarIcon] ? .on : .off + } + } diff --git a/Thor/Thor.entitlements b/Thor/Thor.entitlements index 0c67376..19afff1 100644 --- a/Thor/Thor.entitlements +++ b/Thor/Thor.entitlements @@ -1,5 +1,10 @@ - + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-write + + diff --git a/Thor/zh-Hans.lproj/Main.strings b/Thor/zh-Hans.lproj/Main.strings index 1f67239..70d4129 100644 --- a/Thor/zh-Hans.lproj/Main.strings +++ b/Thor/zh-Hans.lproj/Main.strings @@ -103,3 +103,6 @@ /* Class = "NSMenuItem"; title = "Show Thor in the menu bar"; ObjectID = "LbD-19-0Ga"; */ "LbD-19-0Ga.title" = "在状态栏显示 Thor 图标"; + +/* Class = "NSTextFieldCell"; title = "⇧⌃⌥ ⌘ + T to show/hide"; ObjectID = "Qub-BS-LhT"; */ +"Qub-BS-LhT.title" = "⇧⌃⌥ ⌘ + T 显示/隐藏";