Repository Public
1import AppIntents2import AppKit34/// Actions exposed to the Shortcuts app and Spotlight. They only open things in the browser:5/// none of them reads page content, history or cookies, and none acts on a website.6struct OpenURLIntent: AppIntent {7 static let title = LocalizedStringResource("Open Address in SP Browser", table: "AppIntents")8 static let description = IntentDescription(LocalizedStringResource("Opens a web address in a new tab.", table: "AppIntents"))9 static let openAppWhenRun = true1011 @Parameter(title: LocalizedStringResource("Address", table: "AppIntents")) var address: String1213 @MainActor14 func perform() async throws -> some IntentResult {15 guard let environment = (NSApp.delegate as? AppDelegate)?.environment,16 case .url(let url)? = AddressResolver.resolve(address, engine: environment.settings.activeSearchEngine()),17 ["http", "https"].contains(url.scheme?.lowercased() ?? "") else {18 throw IntentError.invalidAddress19 }20 environment.open(url: url)21 return .result()22 }23}2425struct SearchWebIntent: AppIntent {26 static let title = LocalizedStringResource("Search the Web in SP Browser", table: "AppIntents")27 static let description = IntentDescription(LocalizedStringResource("Searches with the default search engine in a new tab.", table: "AppIntents"))28 static let openAppWhenRun = true2930 @Parameter(title: LocalizedStringResource("Query", table: "AppIntents")) var query: String3132 @MainActor33 func perform() async throws -> some IntentResult {34 guard let environment = (NSApp.delegate as? AppDelegate)?.environment,35 let url = environment.settings.activeSearchEngine().searchURL(for: query) else { throw IntentError.invalidAddress }36 environment.open(url: url)37 return .result()38 }39}4041struct NewPrivateWindowIntent: AppIntent {42 static let title = LocalizedStringResource("New Private Window in SP Browser", table: "AppIntents")43 static let description = IntentDescription(LocalizedStringResource("Opens a private window.", table: "AppIntents"))44 static let openAppWhenRun = true4546 @MainActor47 func perform() async throws -> some IntentResult {48 (NSApp.delegate as? AppDelegate)?.environment.openWindow(isPrivate: true)49 return .result()50 }51}5253enum IntentError: Error, CustomLocalizedStringResourceConvertible {54 case invalidAddress55 var localizedStringResource: LocalizedStringResource { LocalizedStringResource("This is not a web address SP Browser can open.", table: "AppIntents") }56}5758struct SPBrowserShortcuts: AppShortcutsProvider {59 static var appShortcuts: [AppShortcut] {60 AppShortcut(intent: OpenURLIntent(), phrases: ["Open an address in \(.applicationName)"], shortTitle: "Open Address", systemImageName: "globe")61 AppShortcut(intent: SearchWebIntent(), phrases: ["Search the web with \(.applicationName)"], shortTitle: "Search", systemImageName: "magnifyingglass")62 AppShortcut(intent: NewPrivateWindowIntent(), phrases: ["New private window in \(.applicationName)"], shortTitle: "Private Window", systemImageName: "eyeglasses")63 }64}65