iOS/Sources/Launcher/LauncherAppDelegate.swift
mat1th 97834bfd5e
Update swift lint and format + appy fixes (#2585)
## Summary
Swift lint and swiftformat are outdated. This PR does update those +
applies the new formatting form swiftformat.
There is 1 swift file with a manual change:
`Sources/Vehicle/Templates/Areas/CarPlayAreasViewModel.swift`. This is
done because `swiftlint` did create the following swiftlint error:
`error: Cyclomatic Complexity Violation: Function should have complexity
10 or less; currently complexity is 11 (cyclomatic_complexity)`.

Because it does change a lot of files the question is if we want to
finetune the `swiftformat` rules.

## Screenshots
No user facing changes.

## Link to pull request in Documentation repository
NA

## Any other notes
NA
2024-02-22 13:06:39 +01:00

43 lines
1.6 KiB
Swift

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 {
print("launched app: \(app)")
} else if let error {
print("failed to launch app: \(error)")
}
DispatchQueue.main.async { [self] in
didFinishLaunchingMainApp()
}
}
}
func didFinishLaunchingMainApp() {
precondition(Thread.isMainThread)
NSApp.terminate(nil)
}
}