2019-05-20 08:34:47 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2023-02-14 15:10:32 +00:00
|
|
|
// Copyright © 2018-2023 WireGuard LLC. All Rights Reserved.
|
2019-05-20 08:34:47 +00:00
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
class LaunchedAtLoginDetector {
|
|
|
|
static func isLaunchedAtLogin(openAppleEvent: NSAppleEventDescriptor) -> Bool {
|
2021-09-22 17:22:44 +00:00
|
|
|
let now = clock_gettime_nsec_np(CLOCK_UPTIME_RAW)
|
|
|
|
guard openAppleEvent.eventClass == kCoreEventClass && openAppleEvent.eventID == kAEOpenApplication else { return false }
|
|
|
|
guard let url = FileManager.loginHelperTimestampURL else { return false }
|
|
|
|
guard let data = try? Data(contentsOf: url) else { return false }
|
|
|
|
_ = FileManager.deleteFile(at: url)
|
|
|
|
guard data.count == 8 else { return false }
|
|
|
|
let then = data.withUnsafeBytes { ptr in
|
|
|
|
ptr.load(as: UInt64.self)
|
|
|
|
}
|
2021-09-23 04:19:48 +00:00
|
|
|
return now - then <= 20000000000
|
2019-05-22 12:01:05 +00:00
|
|
|
}
|
2019-05-20 08:34:47 +00:00
|
|
|
}
|