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

👌 Prevent hotkey multi-fire (#33)

This commit is contained in:
2021-04-02 18:32:07 +02:00
parent 2925b0ff79
commit faf49fbe1d
3 changed files with 20 additions and 4 deletions

View File

@ -107,6 +107,7 @@ class App {
} }
hotKey.keyDownHandler = { hotKey.keyDownHandler = {
MainMenu.shared.statusItem.button?.performClick(nil) MainMenu.shared.statusItem.button?.performClick(nil)
NSApplication.shared.activate(ignoringOtherApps: true)
} }
} }

View File

@ -84,7 +84,7 @@
<scene sceneID="iyi-IS-7Ps"> <scene sceneID="iyi-IS-7Ps">
<objects> <objects>
<viewController title="Preferences" storyboardIdentifier="preferences" showSeguePresentationStyle="single" id="AW2-rV-rbS" customClass="PrefsVC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController"> <viewController title="Preferences" storyboardIdentifier="preferences" showSeguePresentationStyle="single" id="AW2-rV-rbS" customClass="PrefsVC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="Pf1-A5-3Xz"> <view key="view" wantsLayer="YES" id="Pf1-A5-3Xz">
<rect key="frame" x="0.0" y="0.0" width="462" height="185"/> <rect key="frame" x="0.0" y="0.0" width="462" height="185"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
@ -151,7 +151,7 @@
<constraints> <constraints>
<constraint firstAttribute="trailing" secondItem="JrH-aa-AzL" secondAttribute="trailing" constant="20" symbolic="YES" id="8iM-Xf-ShU"/> <constraint firstAttribute="trailing" secondItem="JrH-aa-AzL" secondAttribute="trailing" constant="20" symbolic="YES" id="8iM-Xf-ShU"/>
<constraint firstAttribute="trailing" secondItem="GSr-K5-3yw" secondAttribute="trailing" constant="20" symbolic="YES" id="AT9-5F-6g1"/> <constraint firstAttribute="trailing" secondItem="GSr-K5-3yw" secondAttribute="trailing" constant="20" symbolic="YES" id="AT9-5F-6g1"/>
<constraint firstItem="YsQ-AZ-Aei" firstAttribute="leading" secondItem="V7b-jv-oCB" secondAttribute="trailing" constant="12" symbolic="YES" id="Bk6-4V-GLk"/> <constraint firstItem="YsQ-AZ-Aei" firstAttribute="leading" secondItem="V7b-jv-oCB" secondAttribute="trailing" constant="8" symbolic="YES" id="Bk6-4V-GLk"/>
<constraint firstItem="YsQ-AZ-Aei" firstAttribute="top" secondItem="V7b-jv-oCB" secondAttribute="top" id="CzF-dC-Jm8"/> <constraint firstItem="YsQ-AZ-Aei" firstAttribute="top" secondItem="V7b-jv-oCB" secondAttribute="top" id="CzF-dC-Jm8"/>
<constraint firstItem="V7b-jv-oCB" firstAttribute="leading" secondItem="MEf-MN-oXt" secondAttribute="leading" id="El4-TW-O0d"/> <constraint firstItem="V7b-jv-oCB" firstAttribute="leading" secondItem="MEf-MN-oXt" secondAttribute="leading" id="El4-TW-O0d"/>
<constraint firstItem="MEf-MN-oXt" firstAttribute="top" secondItem="Pf1-A5-3Xz" secondAttribute="top" constant="20" symbolic="YES" id="FJC-Lx-L8a"/> <constraint firstItem="MEf-MN-oXt" firstAttribute="top" secondItem="Pf1-A5-3Xz" secondAttribute="top" constant="20" symbolic="YES" id="FJC-Lx-L8a"/>
@ -177,7 +177,7 @@
</viewController> </viewController>
<customObject id="eQC-8B-FkX" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> <customObject id="eQC-8B-FkX" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="216" y="341.5"/> <point key="canvasLocation" x="208" y="336"/>
</scene> </scene>
</scenes> </scenes>
</document> </document>

View File

@ -7,10 +7,12 @@
import Cocoa import Cocoa
class MainMenu: NSObject, NSWindowDelegate { class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
static let shared = MainMenu() static let shared = MainMenu()
weak var menuDelegate: NSMenuDelegate? = nil
/** /**
The status bar item with variable length. The status bar item with variable length.
*/ */
@ -106,6 +108,7 @@ class MainMenu: NSObject, NSWindowDelegate {
}) })
statusItem.menu = menu statusItem.menu = menu
statusItem.menu?.delegate = self
} }
} }
@ -321,4 +324,16 @@ class MainMenu: NSObject, NSWindowDelegate {
@objc func terminateApp() { @objc func terminateApp() {
NSApplication.shared.terminate(nil) 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
}
} }