1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 12:00:09 +02:00

👌 Improve handling of global hotkey load on startup

This commit is contained in:
2021-08-31 10:52:49 +02:00
parent e8c2277ef5
commit c9c15d10f9
2 changed files with 19 additions and 16 deletions

View File

@ -647,7 +647,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 57; CURRENT_PROJECT_VERSION = 60;
DEVELOPMENT_TEAM = 8M54J5J787; DEVELOPMENT_TEAM = 8M54J5J787;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = phpmon/Info.plist; INFOPLIST_FILE = phpmon/Info.plist;
@ -655,7 +655,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MARKETING_VERSION = 3.4.1; MARKETING_VERSION = 3.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@ -671,7 +671,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 57; CURRENT_PROJECT_VERSION = 60;
DEVELOPMENT_TEAM = 8M54J5J787; DEVELOPMENT_TEAM = 8M54J5J787;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = phpmon/Info.plist; INFOPLIST_FILE = phpmon/Info.plist;
@ -679,7 +679,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MARKETING_VERSION = 3.4.1; MARKETING_VERSION = 3.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";

View File

@ -89,31 +89,34 @@ class App {
On startup, the preferences should be loaded from the .plist, and we'll enable the shortcut if it is set. On startup, the preferences should be loaded from the .plist, and we'll enable the shortcut if it is set.
*/ */
private func loadGlobalHotkey() { private func loadGlobalHotkey() {
let hotkey = Preferences.preferences[.globalHotkey] as! String? // Make sure we can retrieve the hotkey from preferences; if we cannot, no hotkey is set
if hotkey == nil { guard let hotkey = Preferences.preferences[.globalHotkey] as? String else {
print("No global hotkey loaded")
return return
} }
let keybindPref = GlobalKeybindPreference.fromJson(hotkey!) // Make sure we can parse the JSON into the desired format; if we cannot, no hotkey is set
guard let keybindPref = GlobalKeybindPreference.fromJson(hotkey) else {
if (keybindPref != nil) { print("No global hotkey loaded, could not be parsed!")
self.shortcutHotkey = HotKey(keyCombo: KeyCombo(
carbonKeyCode: keybindPref!.keyCode,
carbonModifiers: keybindPref!.carbonFlags
))
} else {
self.shortcutHotkey = nil self.shortcutHotkey = nil
return
} }
self.shortcutHotkey = HotKey(keyCombo: KeyCombo(
carbonKeyCode: keybindPref.keyCode,
carbonModifiers: keybindPref.carbonFlags
))
} }
/** /**
Sets up the action that needs to occur when the shortcut key is pressed (open the menu). Sets up the action that needs to occur when the shortcut key is pressed (open the menu).
*/ */
private func setupGlobalHotkeyListener() { private func setupGlobalHotkeyListener() {
guard let hotKey = self.shortcutHotkey else { guard let hotkey = self.shortcutHotkey else {
return return
} }
hotKey.keyDownHandler = {
hotkey.keyDownHandler = {
MainMenu.shared.statusItem.button?.performClick(nil) MainMenu.shared.statusItem.button?.performClick(nil)
NSApplication.shared.activate(ignoringOtherApps: true) NSApplication.shared.activate(ignoringOtherApps: true)
} }