diff options
| author | FivePixels <o5pxels@gmail.com> | 2019-01-07 20:13:47 -0600 |
|---|---|---|
| committer | FivePixels <o5pxels@gmail.com> | 2019-01-07 20:13:47 -0600 |
| commit | 33590b7c5b66d4a8abf043f0edd4e32dbd39795c (patch) | |
| tree | 23bb3fb6e9b11dc788a4b7496a8157ca54008f52 /Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper | |
| parent | ac6f551c70d67afe5a76dcfdafcde7eda7748b79 (diff) | |
| download | dwa140shortcut-33590b7c5b66d4a8abf043f0edd4e32dbd39795c.tar.xz dwa140shortcut-33590b7c5b66d4a8abf043f0edd4e32dbd39795c.zip | |
meet?
Diffstat (limited to 'Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper')
3 files changed, 61 insertions, 0 deletions
diff --git a/Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/Info.plist b/Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/Info.plist new file mode 100644 index 0000000..a075677 --- /dev/null +++ b/Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/Info.plist @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleExecutable</key> + <string>$(EXECUTABLE_NAME)</string> + <key>CFBundleIdentifier</key> + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>$(PRODUCT_NAME)</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>1.0.0</string> + <key>CFBundleVersion</key> + <string>1</string> + <key>LSMinimumSystemVersion</key> + <string>$(MACOSX_DEPLOYMENT_TARGET)</string> + <key>NSHumanReadableCopyright</key> + <string>MIT © Sindre Sorhus</string> + <key>LSBackgroundOnly</key> + <true/> + <key>NSPrincipalClass</key> + <string>NSApplication</string> +</dict> +</plist> diff --git a/Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/LaunchAtLoginHelper.entitlements b/Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/LaunchAtLoginHelper.entitlements new file mode 100644 index 0000000..852fa1a --- /dev/null +++ b/Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/LaunchAtLoginHelper.entitlements @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>com.apple.security.app-sandbox</key> + <true/> +</dict> +</plist> 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() |
