Download this file
| 1 | import AppKit |
| 2 | import BaseKit |
| 3 | import RastrilloApple |
| 4 | import SwiftUI |
| 5 | |
| 6 | /// The Mac's side of BaseActions: NSWorkspace for apps (P12), the default |
| 7 | /// browser for Base's own pages. |
| 8 | @MainActor enum MacActions { |
| 9 | static func make(session: BaseSession) -> BaseActions { |
| 10 | BaseActions( |
| 11 | open: { app in open(app) }, |
| 12 | openWeb: { path in |
| 13 | guard let origin = session.signedIn?.origin, let url = URL(string: path, relativeTo: origin)?.absoluteURL else { return } |
| 14 | NSWorkspace.shared.open(url) |
| 15 | }, |
| 16 | signOut: { session.signOut() }, |
| 17 | teams: { await session.teams() }, |
| 18 | switchTo: { await session.switchTo($0) }, |
| 19 | setUpAsk: { Task { await session.setUpAsk() } }) |
| 20 | } |
| 21 | |
| 22 | static func installed(_ bundleID: String) -> URL? { NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID) } |
| 23 | |
| 24 | static func open(_ app: HomeData.App) { |
| 25 | let preference = OpenPreference(rawValue: UserDefaults.standard.string(forKey: OpenPreference.key) ?? "") ?? .app |
| 26 | switch Opener.mac(app, preference: preference, installed: installed) { |
| 27 | case .application(let location): |
| 28 | NSWorkspace.shared.openApplication(at: location, configuration: NSWorkspace.OpenConfiguration()) |
| 29 | case .url(let url): |
| 30 | NSWorkspace.shared.open(url) |
| 31 | case .nowhere: |
| 32 | break |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |