forked from home-assistant/iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLauncherAppDelegate.swift
42 lines (35 loc) · 1.57 KB
/
LauncherAppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import AppKit
@main
class LauncherAppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ note: Notification) {
let bundleIdentifier = Bundle.main.bundleIdentifier!
let appIdentifier = String(bundleIdentifier[..<bundleIdentifier.lastIndex(of: ".")!])
print("launcher identifier: \(bundleIdentifier)")
print("app identifier: \(appIdentifier)")
print("running from \(Bundle.main.bundlePath)")
guard NSRunningApplication.runningApplications(withBundleIdentifier: appIdentifier).isEmpty else {
print("app already launching, not doing anything")
didFinishLaunchingMainApp()
return
}
// we're in HA.app/Contents/Library/LoginItems/Launcher.app, and we want to get our container app
let appURL = Bundle.main.bundleURL.appendingPathComponent("../../../../").resolvingSymlinksInPath()
print("launching app at \(appURL.path)")
let openConfiguration = NSWorkspace.OpenConfiguration()
openConfiguration.activates = false
NSWorkspace.shared.openApplication(at: appURL, configuration: openConfiguration) { [self] app, error in
if let app = app {
print("launched app: \(app)")
} else if let error = error {
print("failed to launch app: \(error)")
}
DispatchQueue.main.async {
didFinishLaunchingMainApp()
}
}
}
func didFinishLaunchingMainApp() {
precondition(Thread.isMainThread)
NSApp.terminate(nil)
}
}