Fix concurrency warnings in MacWebBrowser.
This commit is contained in:
parent
db1b27a98f
commit
d132dd7cee
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
import AppKit
|
import AppKit
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
@MainActor public class MacWebBrowser {
|
@MainActor public class MacWebBrowser {
|
||||||
|
|
||||||
@ -22,11 +23,9 @@ import AppKit
|
|||||||
|
|
||||||
if (inBackground) {
|
if (inBackground) {
|
||||||
|
|
||||||
Task { @MainActor in
|
|
||||||
let configuration = NSWorkspace.OpenConfiguration()
|
let configuration = NSWorkspace.OpenConfiguration()
|
||||||
configuration.activates = false
|
configuration.activates = false
|
||||||
_ = try? await NSWorkspace.shared.open(url, configuration: configuration)
|
NSWorkspace.shared.open(url, configuration: configuration, completionHandler: nil)
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -38,17 +37,12 @@ import AppKit
|
|||||||
///
|
///
|
||||||
/// "Browsers" are applications that can both handle `https` URLs, and display HTML documents.
|
/// "Browsers" are applications that can both handle `https` URLs, and display HTML documents.
|
||||||
public class func sortedBrowsers() -> [MacWebBrowser] {
|
public class func sortedBrowsers() -> [MacWebBrowser] {
|
||||||
guard let httpsIDs = LSCopyAllHandlersForURLScheme("https" as CFString)?.takeRetainedValue() as? [String] else {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let htmlIDs = LSCopyAllRoleHandlersForContentType(kUTTypeHTML, .viewer)?.takeRetainedValue() as? [String] else {
|
let httpsAppURLs = NSWorkspace.shared.urlsForApplications(toOpen: URL(string: "https://apple.com/")!)
|
||||||
return []
|
let htmlAppURLs = NSWorkspace.shared.urlsForApplications(toOpen: UTType.html)
|
||||||
}
|
let browserAppURLs = Set(httpsAppURLs).intersection(Set(htmlAppURLs))
|
||||||
|
|
||||||
let browserIDs = Set(httpsIDs).intersection(Set(htmlIDs))
|
return browserAppURLs.compactMap { MacWebBrowser(url: $0) }.sorted {
|
||||||
|
|
||||||
return browserIDs.compactMap { MacWebBrowser(bundleIdentifier: $0) }.sorted {
|
|
||||||
if let leftName = $0.name, let rightName = $1.name {
|
if let leftName = $0.name, let rightName = $1.name {
|
||||||
return leftName < rightName
|
return leftName < rightName
|
||||||
}
|
}
|
||||||
@ -144,7 +138,7 @@ import AppKit
|
|||||||
configuration.activates = false
|
configuration.activates = false
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = try? await NSWorkspace.shared.open([preparedURL], withApplicationAt: self.url, configuration: configuration)
|
NSWorkspace.shared.open([preparedURL], withApplicationAt: self.url, configuration: configuration, completionHandler: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user