mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 14:53:25 +01:00
27 lines
1007 B
Swift
27 lines
1007 B
Swift
import AppKit
|
|
|
|
// TODO: When targeting macOS 11, convert this to use `App` protocol and remove `NSPrincipalClass` in Info.plist.
|
|
|
|
final class AppDelegate: NSObject, NSApplicationDelegate {
|
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
let bundleIdentifier = Bundle.main.bundleIdentifier!
|
|
let mainBundleIdentifier = bundleIdentifier.replacingOccurrences(of: #"-LaunchAtLoginHelper$"#, with: "", options: .regularExpression)
|
|
|
|
// Ensures the app is not already running.
|
|
guard NSRunningApplication.runningApplications(withBundleIdentifier: mainBundleIdentifier).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()
|