SPB Git

Repository Public License

ShellContributions.swift 5.5 KB 102 lines swift

1import LunarDesign2import NavigatorCore3import SwiftUI45#if canImport(UIKit)6import UIKit7#endif89/// What the shell itself contributes, through the same registry calls as any feature: its commands, its four10/// panels and Help, its three tab layouts, its settings sections and the sidebar's panel shortcuts.11@MainActor12enum ShellContributions {13    static func register(in registry: FeatureRegistry) {14        ShellCommands.register(in: registry)15        registerPanels(in: registry)16        registerLayouts(in: registry)17        registerSettings(in: registry)18    }1920    private static func registerPanels(in registry: FeatureRegistry) {21        registry.register(SidePanelContribution(id: .history, title: T("History"), icon: .symbol("clock.arrow.circlepath")) {22            HistoryPanel(window: $0)23        })24        registry.register(SidePanelContribution(id: .bookmarks, title: T("Bookmarks"), icon: .symbol("bookmark")) {25            BookmarksPanel(window: $0)26        })27        registry.register(SidePanelContribution(id: .downloads, title: T("Downloads"), icon: .symbol("arrow.down.circle")) {28            DownloadsPanel(window: $0)29        })30        registry.register(SidePanelContribution(id: .settings, title: T("Settings"), icon: .symbol("gearshape")) {31            SettingsPanel(window: $0)32        })33        registry.register(SidePanelContribution(id: .help, title: T("Help"), icon: .symbol("questionmark.circle")) {34            HelpPanel(window: $0)35        })3637        func panelState(_ panel: SidePanelID) -> @MainActor (CommandContext) -> ContributionState {38            { ContributionState(isActive: $0.window?.panel == panel) }39        }40        registry.register(SidebarFooterItem(id: "history", label: T("History"), icon: .symbol("clock.arrow.circlepath"), order: 10,41                                            state: panelState(.history), action: .panel(.history)))42        registry.register(SidebarFooterItem(id: "bookmarks", label: T("Bookmarks"), icon: .symbol("bookmark"), order: 20,43                                            state: panelState(.bookmarks), action: .panel(.bookmarks)))44        registry.register(SidebarFooterItem(45            id: "downloads", label: T("Downloads"), icon: .symbol("arrow.down.circle"), order: 30,46            isVisible: { $0.store.downloads != nil },47            state: { context in48                let active = context.store.downloads?.activeCount ?? 049                return ContributionState(isActive: context.window?.panel == .downloads || active > 0,50                                         icon: active > 0 ? .symbol("arrow.down.circle.fill") : nil,51                                         accessibilityValue: active > 0 ? L("%d in progress", active) : nil)52            },53            action: .panel(.downloads)))54        registry.register(SidebarFooterItem(id: "settings", label: T("Settings"), icon: .symbol("gearshape"), order: 1_000,55                                            state: panelState(.settings), action: .panel(.settings)))56    }5758    private static func registerLayouts(in registry: FeatureRegistry) {59        registry.register(TabLayoutContribution(mode: .vertical, title: T("Vertical"), icon: .symbol(TabLayoutMode.vertical.symbolName)) {60            VerticalTabLayout(context: $0)61        })62        registry.register(TabLayoutContribution(mode: .horizontal, title: T("Horizontal"), icon: .symbol(TabLayoutMode.horizontal.symbolName)) {63            HorizontalTabLayout(context: $0)64        })65        registry.register(TabLayoutContribution(mode: .compact, title: T("Compact"), icon: .symbol(TabLayoutMode.compact.symbolName)) {66            CompactTabLayout(context: $0)67        })68    }6970    private static func registerSettings(in registry: FeatureRegistry) {71        typealias ID = ShellSettingsSectionID72        registry.register(SettingsSectionContribution(id: ID.appearance, title: T("Appearance"), icon: .symbol("paintpalette"), order: 10) { _ in73            AppearanceSettingsSection()74        })75        registry.register(SettingsSectionContribution(id: ID.search, title: T("Search engine"), icon: .symbol("magnifyingglass"), order: 20) { _ in76            SearchSettingsSection()77        })78        registry.register(SettingsSectionContribution(id: ID.tabs, title: T("Tabs"), icon: .symbol("square.on.square"), order: 30) {79            TabsSettingsSection(window: $0)80        })81        registry.register(SettingsSectionContribution(id: ID.newTab, title: T("New tab page"), icon: .symbol("sparkles"), order: 40) { _ in82            NewTabSettingsSection()83        })84        #if os(iOS)85        registry.register(SettingsSectionContribution(id: ID.oneHanded, title: T("One-handed use"), icon: .symbol("hand.point.up.left"), order: 50,86                                                      isVisible: { _ in UIDevice.current.userInterfaceIdiom == .phone }) { _ in87            OneHandedSettingsSection()88        })89        #endif90        registry.register(SettingsSectionContribution(id: ID.downloads, title: T("Downloads"), icon: .symbol("arrow.down.circle"), order: 60,91                                                      isVisible: { $0.store.downloads != nil }) { _ in92            DownloadsSettingsSection()93        })94        registry.register(SettingsSectionContribution(id: ID.privacy, title: T("Privacy"), icon: .symbol("hand.raised"), order: 70) {95            PrivacySettingsSection(window: $0)96        })97        registry.register(SettingsSectionContribution(id: ID.about, title: T("About"), icon: .symbol("info.circle"), order: 10_000) { _ in98            AboutSettingsSection()99        })100    }101}102
Files main
Menu

Theme