diff --git a/phpmon/Domain/Core/App.swift b/phpmon/Domain/Core/App.swift index 97f28a9..8ca8ebe 100644 --- a/phpmon/Domain/Core/App.swift +++ b/phpmon/Domain/Core/App.swift @@ -107,6 +107,7 @@ class App { } hotKey.keyDownHandler = { MainMenu.shared.statusItem.button?.performClick(nil) + NSApplication.shared.activate(ignoringOtherApps: true) } } diff --git a/phpmon/Domain/Core/Base.lproj/Main.storyboard b/phpmon/Domain/Core/Base.lproj/Main.storyboard index 26545c4..4a40938 100644 --- a/phpmon/Domain/Core/Base.lproj/Main.storyboard +++ b/phpmon/Domain/Core/Base.lproj/Main.storyboard @@ -84,7 +84,7 @@ - + @@ -151,7 +151,7 @@ - + @@ -177,7 +177,7 @@ - + diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index a7ee16d..b269323 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -7,10 +7,12 @@ import Cocoa -class MainMenu: NSObject, NSWindowDelegate { +class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { static let shared = MainMenu() + weak var menuDelegate: NSMenuDelegate? = nil + /** The status bar item with variable length. */ @@ -106,6 +108,7 @@ class MainMenu: NSObject, NSWindowDelegate { }) statusItem.menu = menu + statusItem.menu?.delegate = self } } @@ -321,4 +324,16 @@ class MainMenu: NSObject, NSWindowDelegate { @objc func terminateApp() { NSApplication.shared.terminate(nil) } + + // MARK: - Menu Delegate + + func menuWillOpen(_ menu: NSMenu) { + // Make sure the shortcut key does not trigger this when the menu is open + App.shared.shortcutHotkey?.isPaused = true + } + + func menuDidClose(_ menu: NSMenu) { + // When the menu is closed, allow the shortcut to work again + App.shared.shortcutHotkey?.isPaused = false + } }