Repository Public License
1import DownloadEngine2import Foundation3import NavigatorCore4import OrbitEngine5import Persistence6import PrivacyEngine7import WebRuntime89/// Typed access to what the shell creates once per run, plus a slot map where a feature publishes a long-lived10/// service for the others. Reach it from anywhere: `store.services`, `context.services`, `window.store.services`.11@MainActor12public final class FeatureServices {13 public let database: NavigatorDatabase14 public let settings: AppSettings15 /// Profiles, spaces, windows and tabs in storage (create a profile or a space here, then open a window on it16 /// with `BrowserStore.openWindow(in:profile:persistence:)`).17 public let orbit: OrbitService18 /// `nil` only in tests that open a store without one.19 public let permissions: PermissionService?20 public let downloads: DownloadManager?21 public let profiles: WebProfileRegistry22 /// The Keychain (service `ai.spboucher.orix.navigator`) in the apps; an in-memory store in tests.23 public let secrets: any SecretStore24 public let favicons: FaviconStore25 /// Directory holding the database, for features that keep files next to it. `nil` in tests without one.26 public let dataDirectory: URL?2728 public static let keychainService = "ai.spboucher.orix.navigator"2930 private var slots: [String: Any] = [:]3132 init(database: NavigatorDatabase, settings: AppSettings, orbit: OrbitService, permissions: PermissionService?,33 downloads: DownloadManager?, profiles: WebProfileRegistry, secrets: any SecretStore, favicons: FaviconStore,34 dataDirectory: URL?) {35 self.database = database; self.settings = settings; self.orbit = orbit; self.permissions = permissions36 self.downloads = downloads; self.profiles = profiles; self.secrets = secrets; self.favicons = favicons37 self.dataDirectory = dataDirectory38 }3940 /// Publishes `service` under `key`. Register in the `storeReady` callback of your feature, once; a second41 /// registration under the same key replaces the first.42 public func register<Service>(_ service: Service, for key: ServiceKey<Service>) { slots[key.name] = service }4344 /// The service another feature published, or `nil` when that feature is absent or not ready: callers must45 /// degrade (hide the button), never crash.46 public func service<Service>(_ key: ServiceKey<Service>) -> Service? { slots[key.name] as? Service }4748 public subscript<Service>(key: ServiceKey<Service>) -> Service? { service(key) }4950 public func unregister<Service>(_ key: ServiceKey<Service>) { slots[key.name] = nil }5152 /// Names of the published services, sorted (diagnostics, tests).53 public var registeredServiceNames: [String] { slots.keys.sorted() }54}55