mirror of
https://github.com/aculix/knotchy.git
synced 2026-10-27 07:15:53 +00:00
29 lines
1.0 KiB
Swift
29 lines
1.0 KiB
Swift
import AppKit
|
|
|
|
enum ChromeExtension {
|
|
/// Set once the Chrome Web Store assigns the item ID; until then the setup window hides the row.
|
|
static let storeURL: URL? = nil
|
|
|
|
struct Browser: Equatable {
|
|
let name: String
|
|
let app: URL
|
|
}
|
|
|
|
// Chromium browsers all install from the Chrome Web Store.
|
|
private static let candidates = [("Chrome", "com.google.Chrome"), ("Edge", "com.microsoft.edgemac"),
|
|
("Brave", "com.brave.Browser"), ("Arc", "company.thebrowser.Browser")]
|
|
|
|
static func installedBrowser() -> Browser? {
|
|
guard storeURL != nil else { return nil }
|
|
for (name, id) in candidates {
|
|
if let app = NSWorkspace.shared.urlForApplication(withBundleIdentifier: id) { return Browser(name: name, app: app) }
|
|
}
|
|
return nil
|
|
}
|
|
|
|
static func open(in browser: Browser) {
|
|
guard let storeURL else { return }
|
|
NSWorkspace.shared.open([storeURL], withApplicationAt: browser.app, configuration: NSWorkspace.OpenConfiguration())
|
|
}
|
|
}
|