aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/WireGuard/UI/macOS/AppDelegate.swift5
-rw-r--r--WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift13
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
+}