diff options
author | Roopesh Chander <roop@roopc.net> | 2019-05-22 17:31:05 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2019-05-22 19:52:21 +0530 |
commit | 493c7b102e4095664860304e5e5d5d151ff7507c (patch) | |
tree | 53e5146105b8e138a64f7bea0a886f5cd6c7dca3 /WireGuard | |
parent | macOS: Workaround for unresponsive main menu after reopen (diff) | |
download | wireguard-apple-493c7b102e4095664860304e5e5d5d151ff7507c.tar.xz wireguard-apple-493c7b102e4095664860304e5e5d5d151ff7507c.zip |
macOS: Ignore bogus reopen because of login item helper
The bogus reopen occurs because the SMLoginItemSetEnabled actually runs
the helper app immediately. The helper app attempts to launch the main
app, causing a reopen Apple event (rapp) to be sent.
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard')
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/AppDelegate.swift | 5 | ||||
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift | 13 |
2 files changed, 17 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift index c897111..453a152 100644 --- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift +++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift @@ -58,6 +58,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { } func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows: Bool) -> Bool { + if let appleEvent = NSAppleEventManager.shared().currentAppleEvent { + if LaunchedAtLoginDetector.isReopenedByLoginItemHelper(reopenAppleEvent: appleEvent) { + return false + } + } if hasVisibleWindows { return true } diff --git a/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift b/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift index 185aced..0d8e3d8 100644 --- a/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift +++ b/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift @@ -4,14 +4,25 @@ import Cocoa class LaunchedAtLoginDetector { + static let launchCode = "LaunchedByWireGuardLoginItemHelper" + static func isLaunchedAtLogin(openAppleEvent: NSAppleEventDescriptor) -> Bool { - let launchCode = "LaunchedByWireGuardLoginItemHelper" guard isOpenEvent(openAppleEvent) else { return false } guard let propData = openAppleEvent.paramDescriptor(forKeyword: keyAEPropData) else { return false } return propData.stringValue == launchCode } + + static func isReopenedByLoginItemHelper(reopenAppleEvent: NSAppleEventDescriptor) -> Bool { + guard isReopenEvent(reopenAppleEvent) else { return false } + guard let propData = reopenAppleEvent.paramDescriptor(forKeyword: keyAEPropData) else { return false } + return propData.stringValue == launchCode + } } private func isOpenEvent(_ event: NSAppleEventDescriptor) -> Bool { return event.eventClass == kCoreEventClass && event.eventID == kAEOpenApplication } + +private func isReopenEvent(_ event: NSAppleEventDescriptor) -> Bool { + return event.eventClass == kCoreEventClass && event.eventID == kAEReopenApplication +} |