22 lines
764 B
Swift
22 lines
764 B
Swift
import AppKit
|
|
|
|
@MainActor
|
|
enum AppLauncher {
|
|
static func launch(_ url: URL) async throws {
|
|
let configuration = NSWorkspace.OpenConfiguration()
|
|
configuration.activates = true
|
|
configuration.promptsUserIfNeeded = false
|
|
|
|
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) in
|
|
NSWorkspace.shared.openApplication(at: url, configuration: configuration) { _, error in
|
|
// AppKit calls this completion on a concurrent queue; only resume the continuation here.
|
|
if let error {
|
|
continuation.resume(throwing: error)
|
|
} else {
|
|
continuation.resume()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|