diff options
Diffstat (limited to 'Sources/WireGuardApp/UI/macOS/LaunchedAtLoginDetector.swift')
-rw-r--r-- | Sources/WireGuardApp/UI/macOS/LaunchedAtLoginDetector.swift | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Sources/WireGuardApp/UI/macOS/LaunchedAtLoginDetector.swift b/Sources/WireGuardApp/UI/macOS/LaunchedAtLoginDetector.swift new file mode 100644 index 0000000..0d8e3d8 --- /dev/null +++ b/Sources/WireGuardApp/UI/macOS/LaunchedAtLoginDetector.swift @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved. + +import Cocoa + +class LaunchedAtLoginDetector { + static let launchCode = "LaunchedByWireGuardLoginItemHelper" + + static func isLaunchedAtLogin(openAppleEvent: NSAppleEventDescriptor) -> Bool { + 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 +} |