From 33590b7c5b66d4a8abf043f0edd4e32dbd39795c Mon Sep 17 00:00:00 2001 From: FivePixels Date: Mon, 7 Jan 2019 20:13:47 -0600 Subject: meet? --- .../LaunchAtLogin/LaunchAtLoginHelper/main.swift | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/main.swift (limited to 'Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/main.swift') diff --git a/Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/main.swift b/Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/main.swift new file mode 100644 index 0000000..ad7fd4f --- /dev/null +++ b/Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/main.swift @@ -0,0 +1,25 @@ +import Cocoa + +final class AppDelegate: NSObject, NSApplicationDelegate { + func applicationDidFinishLaunching(_ notification: Notification) { + let bundleId = Bundle.main.bundleIdentifier! + // TODO: Make this more strict by only replacing at the end + let mainBundleId = bundleId.replacingOccurrences(of: "-LaunchAtLoginHelper", with: "") + + // Ensure the app is not already running + guard NSRunningApplication.runningApplications(withBundleIdentifier: mainBundleId).isEmpty else { + NSApp.terminate(nil) + return + } + + let pathComponents = (Bundle.main.bundlePath as NSString).pathComponents + let mainPath = NSString.path(withComponents: Array(pathComponents[0...(pathComponents.count - 5)])) + NSWorkspace.shared.launchApplication(mainPath) + NSApp.terminate(nil) + } +} + +private let app = NSApplication.shared +private let delegate = AppDelegate() +app.delegate = delegate +app.run() -- cgit v1.2.3