Extending the shell
How a feature target (FeatureOrbit, FeatureCommand, FeaturePrivacy, FeatureReading, FeatureAgent,
FeatureStudio) plugs into the browser shell (NavigatorUI) without editing it.
The shell knows nothing about features. At launch both apps call
NavigatorFeatures.registerAll(in: AppEnvironment.shared.registry) // before AppEnvironment.start()which calls public enum <X>Feature { @MainActor public static func register(in registry: FeatureRegistry) } of
each feature (Sources/Feature<X>/<X>Feature.swift). Everything a feature adds goes through that one function.
The shell's own commands, panels, layouts and settings sections are registered through the same calls
(Sources/NavigatorUI/Extension/ShellCommands.swift, ShellContributions.swift): read them as examples.
1. Rules
- Register once, in
register(in:), synchronously. No registration later, no registration from a view. - Identifiers are stable strings, unique per kind, prefixed by the feature:
orbit.open,shield.panel. Commands are dotted lower-case (^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$). An overlay and a panel must not share an identifier. A duplicate keeps the first registration and adds a line toregistry.issues— the tests fail. - Threading. The registry, every contribution closure,
BrowserStore,WindowModel,TabModel,WebEngineandFeatureServicesare@MainActor. Predicates (isAvailable,isVisible,state,isChecked,isActive(in:), badge closures) run during view updates: they read state, they never mutate it, never block and never start work. Hooks run synchronously on the main actor in registration order: return at once and start aTaskfor anything real. Disk and network never on the main actor: put them in your engine's actor. - Read observable state in predicates (the window, its tabs, engines, your
@Observableper-window state) so that views update; state kept elsewhere will not refresh the chrome. - Never import another feature. Share through
store.services(§9) or run a command by identifier (window.run("agent.summarize")). - Private windows. Check
window.isEphemeral/event.isEphemeral/context.isEphemeralWindowbefore writing anything about a page or a tab: nothing from an ephemeral window may reach disk (§8). - Strings: every user-facing string in your own String Catalog, English and French (Canada) (§10).
- No placeholder contribution: a command that does nothing, a panel with fake content or an inert toolbar item must not be registered.
2. Commands
One action = one NavigatorCommand. The menu bar (Mac), hardware-keyboard commands (iPad), the "…" window
menu (capsule and phone dock), tab and page context menus, the Help panel, the command palette and -ORIXRun
all run commands from the registry.
public struct NavigatorCommand: Identifiable {
public let id: String
public var title: LocalizedText // palette, Help, menus
public var category: CommandCategory // .tabs .navigation .page .view .bookmarks .history .windows .tools .privacy .app, or your own
public var icon: LunarIcon? // .symbol("…") or .glyph(.orbit)
public var shortcut: CommandShortcut?
public var keywords: [String] // localised search terms for the palette
public var placements: [CommandPlacement]
public var hidesWhenUnavailable: Bool // menus drop the item instead of disabling it
public var dynamicTitle: (@MainActor (CommandContext) -> LocalizedText?)? // "Unpin Tab"; nil keeps `title`
public var isAvailable: @MainActor (CommandContext) -> Bool // default: always
public var isChecked: (@MainActor (CommandContext) -> Bool)? // non-nil: shown with a check mark
public var perform: @MainActor (CommandContext) async -> Void
public init(id:title:category:icon:shortcut:keywords:placements:hidesWhenUnavailable:dynamicTitle:isAvailable:isChecked:perform:)
@MainActor public func displayTitle(in context: CommandContext) -> String
}
public struct CommandCategory: Identifiable, Hashable, Sendable { public init(id: String, title: LocalizedText, order: Int) }
public enum MenuBarMenu: String, Sendable, CaseIterable { case app, file, edit, view, history, bookmarks, tools, window, help }
public enum CommandPlacement: Hashable, Sendable {
case menuBar(MenuBarMenu, group: Int, order: Int) // `.tools` is the menu for what fits nowhere else
case windowMenu(group: Int, order: Int) // "…" menu: capsule (Mac, iPad) and phone dock
case tabContextMenu(group: Int, order: Int) // context.tab is the tab that was clicked
case pageContextMenu(order: Int) // Mac: any element; iOS: links. After WebKit's items
}
public struct CommandShortcut: Hashable, Sendable, CustomStringConvertible {
public enum Key: Hashable, Sendable { case character(Character), tab, `return`, escape, delete, space, upArrow, downArrow, leftArrow, rightArrow }
public struct Modifiers: OptionSet, Hashable, Sendable { static let command, shift, option, control }
public init(_ key: Key, modifiers: Modifiers = .command)
public init(_ character: Character, modifiers: Modifiers = .command)
public var keyCaps: [String] // ["⇧", "⌘", "T"]
public var keyboardShortcut: KeyboardShortcut // SwiftUI
}
@MainActor public struct CommandContext {
public let environment: AppEnvironment
public let store: BrowserStore
public let window: WindowModel? // nil when no browser window has focus
public let tab: TabModel? // the selected tab, or the tab the command was invoked on
public var source: CommandSource // .menuBar .windowMenu .contextMenu .toolbar .sidebar .palette .help .launchArgument .feature
public var isCompactWidth: Bool
public var registry: FeatureRegistry; public var services: FeatureServices; public var settings: AppSettings
public var engine: WebEngine?; public var url: URL?
public var hasPage: Bool // not the new-tab page
public var isWebPage: Bool // http(s)
public var isEphemeralWindow: Bool
public init(environment:store:window:tab:source:isCompactWidth:)
public func targeting(_ tab: TabModel?, source: CommandSource? = nil) -> CommandContext
}Groups separate runs of menu items with a divider; order sorts inside a group. The shell uses multiples of 10
for both (see the table in §12) so that a feature can slot in between: .menuBar(.view, group: 45, order: 10).
Running commands:
registry.commands // [NavigatorCommand], registration order
registry.command("orbit.open") // NavigatorCommand?
await registry.run("orbit.open", in: context) // Bool: false if unknown or unavailable
registry.perform("orbit.open", in: context) // fire and forget
window.commandContext(tab:source:isCompactWidth:) // a context for a window
window.run("orbit.open") // from a button
registry.commandsByCategory() // for a palette: [(category, commands)]
registry.commands(in: .view) // [[NavigatorCommand]] runs of a menuDefault shortcuts must not collide (registry.shortcutCollisions, tested) and must not take a system or
text-editing shortcut (⌘Q ⌘H ⌘M ⌘C ⌘V ⌘X ⌘Z ⌘A ⇧⌘Z ⇥ space). Taken by the shell: §12.
3. Side panels
Right-hand panel on Mac and iPad (348 pt unless preferredWidth), a sheet on iPhone. The shell draws the
header (icon, title, close); your view fills the rest and gets BrowserStore and the Lunar theme from the
environment.
public struct SidePanelID: RawRepresentable, Hashable, Sendable, Identifiable, ExpressibleByStringLiteral
// shell: .history .bookmarks .downloads .settings .help
public struct SidePanelContribution: Identifiable {
public init<Content: View>(id: SidePanelID, title: LocalizedText, icon: LunarIcon, preferredWidth: CGFloat? = nil,
@ViewBuilder content: @escaping @MainActor (WindowModel) -> Content)
}
window.panel = "shield.panel"; window.togglePanel("shield.panel"); window.panel = nilRegister a command that opens it (and place it in a menu) — a panel nothing opens is unreachable.
4. Toolbar items, sidebar, window badges
public enum ContributionAction {
case command(String) // disabled while the command is unavailable
case panel(SidePanelID) // toggles
case overlay(String) // toggles
case perform(@MainActor (CommandContext) -> Void)
case popover(@MainActor (WindowModel) -> AnyView) // popover; a sheet from the phone menu
}
public struct ContributionState: Equatable, Sendable {
public init(isActive: Bool = false, badge: Int? = nil, isEnabled: Bool = true, icon: LunarIcon? = nil, accessibilityValue: String? = nil)
}
public struct ToolbarItemPlacement: OptionSet {
static let addressField // inside the address field, before Reload (Mac, iPad) and in the phone address pill: page indicators
static let capsule // a capsule button after Share (Mac, iPad); on iPhone an entry of the dock "…" menu
}
public struct ToolbarItemContribution: Identifiable {
public init(id: String, label: LocalizedText, icon: LunarIcon, placement: ToolbarItemPlacement, order: Int = 100,
isVisible: @escaping @MainActor (CommandContext) -> Bool = { _ in true }, // e.g. { $0.isWebPage }
state: @escaping @MainActor (CommandContext) -> ContributionState = { _ in .normal },
action: ContributionAction)
}
public struct SidebarSectionContribution: Identifiable { // a block of the vertical sidebar (268 pt wide)
public enum Placement { case aboveTabs, belowTabs }
public init<Content: View>(id: String, placement: Placement, order: Int = 100,
isVisible: @escaping @MainActor (WindowModel) -> Bool = { _ in true },
@ViewBuilder content: @escaping @MainActor (WindowModel) -> Content)
}
public struct SidebarFooterItem: Identifiable { // icon row at the bottom; first five by order, the rest in "More"
public init(id: String, label: LocalizedText, icon: LunarIcon, order: Int = 100, isVisible:state:action:)
} // shell: history 10, bookmarks 20, downloads 30, settings 1000
public struct WindowBadge: Equatable, Sendable { public init(label: String, icon: LunarIcon, status: LunarStatus = .neutral) }
public struct WindowBadgeContribution: Identifiable {
public init(id: String, order: Int = 100, badge: @escaping @MainActor (WindowModel) -> WindowBadge?)
}A window badge marks the chrome of a kind of window (private, focus): it is drawn in the sidebar's space header,
at the leading edge of the toolbar when the sidebar is not shown, and in the phone address pill.
"Phone menu entries" are commands placed in .windowMenu plus capsule toolbar items: there is no separate
kind. The capsule has room for about three extra buttons at the minimum window width; prefer addressField
for page indicators and the window menu for the rest.
5. Window overlays
Full-window modal surfaces (the Orbit view, the command palette).
public enum WindowOverlayStyle { case scrim(alignment: Alignment = .center, maxWidth: CGFloat? = 640, maxHeight: CGFloat? = nil), fullCover }
public struct WindowOverlayContribution: Identifiable {
public init<Content: View>(id: String, style: WindowOverlayStyle, dismissesOnOutsideTap: Bool = true,
@ViewBuilder content: @escaping @MainActor (WindowModel) -> Content)
}
window.present(overlay: "command.palette"); window.toggle(overlay:); window.dismissOverlay(); window.presentedOverlayID
window.focusPage() // what dismissOverlay() does after hidingOne overlay per window; presenting replaces the one shown. Escape always dismisses, then keyboard focus goes
back to the page. .scrim content brings its own surface (.lunarGlass(...)); .fullCover gets the window
backdrop. A text field in your overlay takes focus itself (@FocusState, .onAppear).
6. Web area, tab content, chrome visibility, tab layouts
@MainActor public protocol WebAreaContentProvider: AnyObject {
var id: String { get }
var priority: Int { get } // higher wins. Reader 100, Split 200, full takeover 300
func isActive(in window: WindowModel) -> Bool // observable state only
func makeContent(_ context: WebAreaContext) -> AnyView
}
@MainActor public final class WebAreaProvider: WebAreaContentProvider { // closure form
public init<Content: View>(id: String, priority: Int, isActive: @escaping @MainActor (WindowModel) -> Bool,
@ViewBuilder content: @escaping @MainActor (WebAreaContext) -> Content)
}
@MainActor public struct WebAreaContext { window; webOptions: WebEngineViewOptions; bottomChromeInset: CGFloat; isCompactWidth: Bool }
registry.register(webArea: provider); registry.activeWebAreaProvider(for: window)
public struct TabContentView: View { // one tab: web view, new-tab page, error / certificate / blocked pages
public init(window: WindowModel, tab: TabModel, options: WebEngineViewOptions = .init(), bottomInset: CGFloat = 0)
}The shell asks providers from the highest priority down and uses the first that is active; with none it shows
TabContentView for the selected tab. The shell keeps drawing banners, the find bar, page prompts and toasts on
top, and the rounded frame around. Split composes several TabContentViews (activate their engines with
store.pool.activate(tab.engine); pass context.webOptions); Reader returns its article view.
Chrome visibility (Focus):
public struct ChromeElements: OptionSet { static let sidebar, tabStrip, toolbar, panel, all }
window.setChromeHidden([.sidebar, .tabStrip], requester: "orbit.focus") // [] releases
window.hiddenChrome // union of all requestsWhoever hides the toolbar must offer a way back (a command with a shortcut): the shell does not override it.
Tab layouts (Mac, iPad; the phone has its own):
public struct TabLayoutContribution: Identifiable {
public init<Content: View>(mode: TabLayoutMode, title: LocalizedText, icon: LunarIcon,
@ViewBuilder body: @escaping @MainActor (TabLayoutContext) -> Content)
}
@MainActor public struct TabLayoutContext { window; windowControlsInset: CGFloat; hiddenChrome: ChromeElements }
registry.supportedLayouts // shell: [.vertical, .horizontal, .compact]; + .grid / .orbit once registeredbody draws everything of the window except the side panel, from the public blocks SidebarView(window:),
TabStripView(window:isCondensed:), NewTabButton(window:), BrowserToolbarRow(window:leadingReserve:) and
WebAreaView(window:); keep windowControlsInset free at the leading edge of the first row and honour
hiddenChrome. The commands view.layout.grid / view.layout.orbit and the Settings choice exist already and
become available when the renderer is registered.
7. Settings sections
public struct SettingsSectionContribution: Identifiable {
public init<Content: View>(id: String, title: LocalizedText, icon: LunarIcon, order: Int,
isVisible: @escaping @MainActor (WindowModel) -> Bool = { _ in true },
@ViewBuilder content: @escaping @MainActor (WindowModel) -> Content)
}content is stacked vertically inside the section's card. Shell sections: appearance 10, search 20, tabs 30,
newtab 40, onehanded 50 (iPhone), downloads 60, privacy 70, about 10 000 (always last); features use 100…9 999.
Persist values with store.database.settings and your own SettingKeys. Open at a section with
window.panel = .settings; window.settingsSectionRequest = "shield.settings" or -ORIXSettingsSection <id>.
8. Engine hooks, profiles, private windows
public struct EngineHooks: Identifiable {
public init(id: String,
profileContextCreated: (@MainActor (ProfileEvent) -> Void)? = nil, // once per ProfileContext: attach rule lists here
windowOpened: (@MainActor (WindowEvent) -> Void)? = nil,
windowClosed: (@MainActor (WindowEvent) -> Void)? = nil,
configureSettings: (@MainActor (inout WebEngineSettings, _ profile: Profile, _ isEphemeral: Bool) -> Void)? = nil,
engineCreated: (@MainActor (TabEvent) -> Void)? = nil, // install user scripts / stylesheets
engineWillClose: (@MainActor (TabEvent) -> Void)? = nil,
navigationCommitted: (@MainActor (NavigationEvent) -> Void)? = nil, // also same-document navigations (same commitCount, new url)
navigationFinished: (@MainActor (NavigationEvent) -> Void)? = nil, // loaded, no error page; title is final
tabSelected: (@MainActor (TabEvent, _ previous: TabID?) -> Void)? = nil,
tabClosed: (@MainActor (TabEvent) -> Void)? = nil)
}
ProfileEvent: store, profile, context: ProfileContext, isGhost
WindowEvent: store, window, windowID, profile, space, isEphemeral, isGhost
TabEvent: store, window, tab, engine, tabID, windowID, spaceID, profile, profileContext, isGhost, isEphemeral
NavigationEvent: tab: TabEvent, url, title, commitCount, engine, profile, isGhost, isEphemeral
registry.whenStoreReady { store in … } // database open, services created, before windows are restoredOrder at launch: register(in:) → store opens → whenStoreReady callbacks → restored windows
(windowOpened, profileContextCreated, engineCreated per tab) → first window on screen. Create your
long-lived services in whenStoreReady, so that hooks can use them.
Windows, profiles, spaces:
window.profile: Profile; window.space: OrbitSpace; window.persistence: WindowPersistence; window.isEphemeral
window.dataProfileID // whose bookmarks/history the window reads (the default profile for a private window)
store.profile; store.space // the default profile and its first space
store.openWindow(in: space, profile: profile, persistence: .normal | .ephemeral, url: nil) -> WindowModel
store.windows(of: profileID); store.canMoveTab(_:to:); store.profileContext(for: profile).normal needs a stored profile and space (store.services.orbit.createProfile(name:tint:),
.createSpace(profile:name:…)); such windows are restored at the next launch with their profile.
.ephemeral is the private window: the store never sends it or its tabs to SessionOrchestrator, it has no
recently-closed tabs, WebRuntime records no history for its (ghost) profile, permission answers stay in memory,
its site icons stay in memory, its tabs are not suggested to other windows and cannot be moved to a normal
window. It always runs on a ghost profile: pass one (GhostSession(database:) of PrivacyEngine gives a profile
and a space) or pass a standard profile and the store derives a ghost one. When the last window of a ghost
profile closes, the store ends the WebKit session, the in-memory permissions and the icons.
anEphemeralWindowWritesNothing (NavigatorUITests) proves zero rows and zero files; keep it true: a feature
must not write anything when isEphemeral is true. Mark the chrome with a WindowBadgeContribution:
registry.register(WindowBadgeContribution(id: "ghost.badge") { window in
window.isEphemeral ? WindowBadge(label: L("Private"), icon: .glyph(.ghost), status: .accent) : nil
})On the Mac and iPad a new window gets its own scene; on iPhone the single scene switches to it and falls back to another window when it closes.
Per-window and per-tab feature state (one instance per type, created on first use, released with the owner):
window.featureState(SplitState.self) { SplitState() } // make it @Observable
window.existingFeatureState(SplitState.self) // nil if never created — use this in predicates
tab.featureState(ReaderState.self) { ReaderState() }; tab.existingFeatureState(ReaderState.self); tab.window9. Services
@MainActor public final class FeatureServices { // store.services, context.services
public let database: NavigatorDatabase
public let settings: AppSettings
public let orbit: OrbitService
public let permissions: PermissionService? // nil only in tests without one
public let downloads: DownloadManager?
public let profiles: WebProfileRegistry
public let secrets: any SecretStore // Keychain, service "ai.spboucher.orix.navigator"; in memory in tests
public let favicons: FaviconStore
public let dataDirectory: URL?
public func register<Service>(_ service: Service, for key: ServiceKey<Service>)
public func service<Service>(_ key: ServiceKey<Service>) -> Service? // also services[key]
}
public struct ServiceKey<Service>: Hashable, Sendable { public init(_ name: String) } // in NavigatorCoreTo offer a service to other features without being imported by them, put the contract in a new NavigatorCore
file named after your feature (allowed by AGENT_RULES), keep the implementation in the feature, publish it in
whenStoreReady:
// Sources/NavigatorCore/FeatureAgent+Services.swift
public protocol PageSummarizing: Sendable { func summarize(tab: TabID) async throws -> String }
extension ServiceKey where Service == any PageSummarizing { public static let pageSummarizer = ServiceKey("agent.pageSummarizer") }
// FeatureAgent
registry.whenStoreReady { store in store.services.register(Summarizer(store) as any PageSummarizing, for: .pageSummarizer) }
// FeatureReading — degrade when absent, never crash
if let summarizer = store.services.service(.pageSummarizer) { … } else { /* hide the button */ }10. Localisation
Each feature has its own catalog, Sources/Feature<X>/Resources/Localizable.xcstrings (source language en,
plus fr-CA), in its own bundle. The key is the English text. <X>Feature.swift already declares:
let strings = FeatureStrings(module: "FeatureOrbit", bundle: .module)
func L(_ key: String, _ arguments: any CVarArg...) -> String // a string now: L("%d tabs", count)
func T(_ key: String) -> LocalizedText // a title for the registry: T("Open Orbit")Always call L("literal") / T("literal") with a string literal: NavigatorFeaturesTests scans your sources
for those calls and fails on a key missing in English or French (Canada), on differing %@/%d placeholders
and on catalog entries no code uses. Registry titles must be T(...), never .verbatim.
11. Launch arguments (screenshots without input)
-ORIXShow <id> a built-in target, else an overlay id, else a panel id, else a command id
-ORIXRun <command-id> repeatable, run in order after -ORIXShow, on the first window
-ORIXSettingsSection <id> opens Settings scrolled to a section
-ORIXTabLayout vertical|horizontal|compact|grid|orbitscripts/shot.sh mac orbit -- -ORIXShow orbit.view. Every feature screen must be reachable this way: give
each a command (state that needs several steps: -ORIXRun a -ORIXRun b).
12. What the shell registers
Menu groups (group): file 10 new · 20 open · 30 close · 40 tab state · 50 share/export; edit 10 find · 20
copy; view 10 reload · 20 zoom · 30 page mode · 40 sidebar/panels · 50 layouts; history 10 back/forward · 20
history · 30 clear; bookmarks 10; window 10 next/previous · 20 move · 30 select; help 10 · 20; app 10.
Window menu: 10 new · 20 panels/bookmark · 30 page · 40 layouts · 90 settings/help.
Tab context menu: 10 tab state · 20 move · 30 copy · 40 close.
| Command id | Title | Shortcut |
|---|---|---|
tab.new |
New Tab | ⌘T |
tab.close |
Close Tab | ⌘W |
tab.closeOthers |
Close Other Tabs | |
tab.reopenClosed |
Reopen Closed Tab | ⇧⌘T |
tab.reload |
Reload (tab context menu) | |
tab.duplicate |
Duplicate Tab | |
tab.pin |
Pin Tab / Unpin Tab | |
tab.mute |
Mute Tab / Unmute Tab | |
tab.moveLeft, tab.moveRight |
Move Tab Left / Right | |
tab.moveToNewWindow |
Move Tab to New Window | |
tab.next, tab.previous |
Show Next / Previous Tab | ⌃⇥, ⌃⇧⇥ |
tabs.showSwitcher |
Show All Tabs (compact width) | |
tab.select.1 … tab.select.8, tab.select.last |
Show Tab N / Show Last Tab | ⌘1 … ⌘8, ⌘9 |
window.new |
New Window | ⌘N |
window.close (Mac) |
Close Window | ⇧⌘W |
omnibox.focus |
Open Location… | ⌘L |
nav.back, nav.forward |
Back, Forward | ⌘[, ⌘] |
page.reload, page.reloadFromOrigin, page.stop |
Reload Page, Reload from Origin, Stop | ⌘R, ⇧⌘R, ⌘. |
find.show, find.next, find.previous |
Find in Page…, Find Next, Find Previous | ⌘F, ⌘G, ⇧⌘G |
bookmark.add |
Bookmark This Page… | ⌘D |
page.copyURL |
Copy Page Address | ⇧⌘C |
page.share, page.savePDF, page.print |
Share…, Save as PDF…, Print… | –, –, ⌘P |
page.toggleContentMode |
Request Mobile Site / Request Desktop Site | |
view.zoomIn, view.zoomOut, view.zoomReset |
Zoom In, Zoom Out, Actual Size | ⌘+, ⌘-, ⌘0 |
view.toggleSidebar |
Hide Sidebar / Show Sidebar | ⌘S |
view.layout.vertical .horizontal .compact .grid .orbit |
Vertical / Horizontal / Compact Tabs, Grid of Tabs, Orbit Tabs | |
panel.history, panel.bookmarks, panel.downloads, panel.settings |
Show History, Show Bookmarks, Show Downloads, Settings… | ⌘Y, ⌥⌘B, ⇧⌘J, ⌘, |
panel.close |
Close Side Panel | |
privacy.clearData |
Clear Browsing Data… | |
help.show, help.welcome |
ORIX Navigator Help, Show Welcome Screens | ⇧⌘/ |
57 commands on the Mac (56 on iOS, which has no window.close); constants in ShellCommandID.
13. A complete minimal feature
import LunarDesign
import NavigatorCore
import NavigatorUI
import SwiftUI
import WebRuntime
@MainActor @Observable final class PulseWindowState { var count = 0 }
@MainActor final class PulseService { // long-lived, created once per store
private(set) var pagesSeen: [TabID: Int] = [:]
func note(_ event: NavigationEvent) {
guard !event.isEphemeral else { return } // nothing about a private page is kept
pagesSeen[event.tab.tabID, default: 0] += 1
}
func forget(_ tab: TabID) { pagesSeen[tab] = nil }
}
extension ServiceKey where Service == PulseService { static let pulse = ServiceKey("pulse.service") }
public enum PulseFeature {
@MainActor public static func register(in registry: FeatureRegistry) {
let category = CommandCategory(id: "pulse", title: T("Pulse"), order: 200)
// Service, then the hooks that feed it.
registry.whenStoreReady { store in store.services.register(PulseService(), for: .pulse) }
registry.register(EngineHooks(
id: "pulse",
navigationFinished: { event in event.tab.store.services.service(.pulse)?.note(event) },
tabClosed: { event in event.store.services.service(.pulse)?.forget(event.tabID) }))
// Command: opens the panel. Menu bar (View), window menu, shortcut, palette, Help, -ORIXRun.
registry.register(NavigatorCommand(
id: "pulse.show", title: T("Show Pulse"), category: category, icon: .glyph(.blink),
shortcut: CommandShortcut("u", modifiers: [.command, .option]), keywords: [L("activity")],
placements: [.menuBar(.view, group: 45, order: 10), .windowMenu(group: 25, order: 10)],
isAvailable: { $0.window != nil },
isChecked: { $0.window?.panel == "pulse.panel" },
perform: { $0.window?.togglePanel("pulse.panel") }))
registry.register(NavigatorCommand(
id: "pulse.overview", title: T("Pulse Overview"), category: category, icon: .glyph(.blink),
isAvailable: { $0.window != nil }, perform: { $0.window?.present(overlay: "pulse.overview") }))
// Panel.
registry.register(SidePanelContribution(id: "pulse.panel", title: T("Pulse"), icon: .glyph(.blink)) { window in
PulsePanel(window: window)
})
// Toolbar item: only on web pages, shows a count, opens the panel.
registry.register(ToolbarItemContribution(
id: "pulse.indicator", label: T("Pulse"), icon: .glyph(.blink), placement: .addressField,
isVisible: { $0.isWebPage },
state: { context in
let seen = context.tab.flatMap { context.services.service(.pulse)?.pagesSeen[$0.id] } ?? 0
return ContributionState(isActive: context.window?.panel == "pulse.panel", badge: seen,
accessibilityValue: L("%d pages", seen))
},
action: .command("pulse.show")))
// Overlay.
registry.register(WindowOverlayContribution(id: "pulse.overview", style: .scrim(alignment: .top, maxWidth: 560)) { window in
PulseOverview(window: window)
})
// Settings section.
registry.register(SettingsSectionContribution(id: "pulse.settings", title: T("Pulse"), icon: .glyph(.blink), order: 300) { _ in
PulseSettings()
})
}
}
struct PulsePanel: View {
@Environment(\.lunarTheme) private var theme
@Environment(BrowserStore.self) private var store
let window: WindowModel
var body: some View {
let state = window.featureState(PulseWindowState.self) { PulseWindowState() }
VStack(alignment: .leading, spacing: LunarSpacing.sm) {
Text(L("%d pages", store.services.service(.pulse)?.pagesSeen.values.reduce(0, +) ?? 0))
.lunarFont(.headline).foregroundStyle(theme.textPrimary)
Button(L("Count")) { state.count += 1 }.buttonStyle(.lunar(.secondary))
Button(L("Pulse Overview")) { window.run("pulse.overview") }.buttonStyle(.lunar(.primary))
}
.padding(LunarSpacing.md)
}
}PulseOverview and PulseSettings are ordinary views. Screenshots:
scripts/shot.sh mac pulse -- -ORIXOpenURL https://example.com -ORIXShow pulse.panel, -ORIXShow pulse.overview,
-ORIXSettingsSection pulse.settings.
14. Checklist before you report
- Everything registered from
<X>Feature.register(in:); no edit outside your directories (new shared contracts: one new fileSources/NavigatorCore/Feature<X>+….swift). - Identifiers prefixed and unique;
registry.issuesempty. - Each screen has a command; each command has a
T("…")title in en and fr-CA; shortcuts do not collide. - Predicates are pure and read observable state; hooks return at once; no disk or network on the main actor.
- Nothing is written, indexed, logged or cached for an ephemeral window; secrets only in
services.secrets. - Compact width works: commands in
.windowMenu, panels as sheets,capsuleitems in the dock menu. -
swift test --filter "Feature<X>Tests|NavigatorFeaturesTests|NavigatorUITests"green, zero warnings in your target;scripts/build.sh macandiosbuild; screenshots taken withscripts/shot.shand looked at.