Fix deprecation warning.

This commit is contained in:
Brent Simmons 2024-04-06 18:21:03 -07:00
parent feb1e77424
commit ced40d5e8a
1 changed files with 9 additions and 6 deletions

View File

@ -14,18 +14,21 @@ public class MacWebBrowser {
/// Opens a URL in the default browser.
@discardableResult public class func openURL(_ url: URL, inBackground: Bool = false) -> Bool {
// TODO: make this function async
guard let preparedURL = url.preparedForOpeningInBrowser() else {
return false
}
if (inBackground) {
do {
try NSWorkspace.shared.open(preparedURL, options: [.withoutActivation], configuration: [:])
return true
}
catch {
return false
Task {
let configuration = NSWorkspace.OpenConfiguration()
configuration.activates = false
_ = try? await NSWorkspace.shared.open(url, configuration: configuration)
}
return true
}
return NSWorkspace.shared.open(preparedURL)