23 lines
713 B
Swift
23 lines
713 B
Swift
import Cocoa
|
|
|
|
@NSApplicationMain
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
|
|
|
let mainBundleId = "com.west2online.ClashX"
|
|
|
|
// 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)
|
|
}
|
|
|
|
}
|
|
|