SPB Git

Repository Public License

EngineHooks.swift 5.3 KB 109 lines swift

1import Foundation2import NavigatorCore3import WebRuntime45/// A profile got its WebKit context (data store, rule lists, scripts). Fired once per `ProfileContext`: once6/// for a standard profile, once per private session for a ghost profile.7@MainActor8public struct ProfileEvent {9    public let store: BrowserStore10    public let profile: Profile11    public let context: ProfileContext12    public var isGhost: Bool { profile.isGhost }13}1415@MainActor16public struct WindowEvent {17    public let store: BrowserStore18    public let window: WindowModel19    public var windowID: WindowID { window.id }20    public var profile: Profile { window.profile }21    public var space: OrbitSpace { window.space }22    /// The window is never written to the session (private window).23    public var isEphemeral: Bool { window.isEphemeral }24    public var isGhost: Bool { window.profile.isGhost }25}2627@MainActor28public struct TabEvent {29    public let store: BrowserStore30    public let window: WindowModel31    public let tab: TabModel32    public var engine: WebEngine { tab.engine }33    public var tabID: TabID { tab.id }34    public var windowID: WindowID { window.id }35    public var spaceID: SpaceID { window.space.id }36    public var profile: Profile { window.profile }37    public var profileContext: ProfileContext { tab.engine.profile }38    public var isGhost: Bool { tab.engine.profile.isGhost }39    /// Nothing about this tab may be written to disk.40    public var isEphemeral: Bool { window.isEphemeral }41}4243@MainActor44public struct NavigationEvent {45    public let tab: TabEvent46    /// The document committed in the main frame.47    public let url: URL48    /// The title known at that moment (often empty at commit; the real one at finish).49    public let title: String50    /// `engine.commitCount` for this document: the same value in the commit and the finish event of one load.51    public let commitCount: Int52    public var engine: WebEngine { tab.engine }53    public var profile: Profile { tab.profile }54    public var isGhost: Bool { tab.isGhost }55    public var isEphemeral: Bool { tab.isEphemeral }56}5758/// Callbacks on the life of profiles, windows, tabs and pages. Every closure is optional and runs on the main59/// actor, synchronously, in registration order: return quickly and start a `Task` for real work.60public struct EngineHooks: Identifiable {61    public let id: String62    /// Attach content rule lists, set `internalContentProvider`…63    public var profileContextCreated: (@MainActor (ProfileEvent) -> Void)?64    public var windowOpened: (@MainActor (WindowEvent) -> Void)?65    /// The window is gone (its tabs were closed without `tabClosed`: they are kept as recently closed, or66    /// discarded for an ephemeral window).67    public var windowClosed: (@MainActor (WindowEvent) -> Void)?68    /// Adjusts the settings of an engine about to be created for a tab of `profile` (`reportsSelection` for69    /// Lens, `mirrorsConsole` for Dev…). Pop-ups inherit the settings of the tab that opened them.70    public var configureSettings: (@MainActor (inout WebEngineSettings, _ profile: Profile, _ isEphemeral: Bool) -> Void)?71    /// A tab got its engine (new tab, restored tab, pop-up, duplicate). Install user scripts and stylesheets72    /// here: the engine re-installs them when its web view is recreated.73    public var engineCreated: (@MainActor (TabEvent) -> Void)?74    /// The engine is about to be closed (tab closed, window closed). Moving a tab to another window does not close its engine.75    public var engineWillClose: (@MainActor (TabEvent) -> Void)?76    /// A main-frame document committed.77    public var navigationCommitted: (@MainActor (NavigationEvent) -> Void)?78    /// The committed document finished loading without an error page.79    public var navigationFinished: (@MainActor (NavigationEvent) -> Void)?80    /// The tab became the selected tab of its window. `previous` is the tab that was selected before.81    public var tabSelected: (@MainActor (TabEvent, _ previous: TabID?) -> Void)?82    /// The user closed the tab.83    public var tabClosed: (@MainActor (TabEvent) -> Void)?8485    public init(id: String,86                profileContextCreated: (@MainActor (ProfileEvent) -> Void)? = nil,87                windowOpened: (@MainActor (WindowEvent) -> Void)? = nil,88                windowClosed: (@MainActor (WindowEvent) -> Void)? = nil,89                configureSettings: (@MainActor (inout WebEngineSettings, _ profile: Profile, _ isEphemeral: Bool) -> Void)? = nil,90                engineCreated: (@MainActor (TabEvent) -> Void)? = nil,91                engineWillClose: (@MainActor (TabEvent) -> Void)? = nil,92                navigationCommitted: (@MainActor (NavigationEvent) -> Void)? = nil,93                navigationFinished: (@MainActor (NavigationEvent) -> Void)? = nil,94                tabSelected: (@MainActor (TabEvent, _ previous: TabID?) -> Void)? = nil,95                tabClosed: (@MainActor (TabEvent) -> Void)? = nil) {96        self.id = id97        self.profileContextCreated = profileContextCreated98        self.windowOpened = windowOpened99        self.windowClosed = windowClosed100        self.configureSettings = configureSettings101        self.engineCreated = engineCreated102        self.engineWillClose = engineWillClose103        self.navigationCommitted = navigationCommitted104        self.navigationFinished = navigationFinished105        self.tabSelected = tabSelected106        self.tabClosed = tabClosed107    }108}109
Files main
Menu

Theme