mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-21 04:33:30 +01:00
[AltServer] Adds option to Launch at Login
This commit is contained in:
25
Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/main.swift
vendored
Normal file
25
Carthage/Checkouts/LaunchAtLogin/LaunchAtLoginHelper/main.swift
vendored
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user