Repository Public License
1// ORIX Secure2// File: App/Sources/Core/Router.swift3// Description: Navigation state shared by the iPhone tab layout and the iPad sidebar layout.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import ORIXSecureEngines8import SwiftUI910/// Every top-level screen of the app.11enum Destination: String, Hashable, CaseIterable, Identifiable {12 case dashboard13 case securityAudit, checklist, privacy, investigations14 case storage, photoCleanup, fileCleanup15 case linkAnalyzer, fileScanner, network, device, battery16 case reports, actions, settings1718 var id: String { rawValue }1920 var title: LocalizedStringKey {21 switch self {22 case .dashboard: "Overview"23 case .securityAudit: "Security Audit"24 case .checklist: "Security Checklist"25 case .privacy: "Privacy Audit"26 case .investigations: "Investigations"27 case .storage: "Storage"28 case .photoCleanup: "Photo Cleanup"29 case .fileCleanup: "File Cleanup"30 case .linkAnalyzer: "Link Analyser"31 case .fileScanner: "File Scanner"32 case .network: "Network Lab"33 case .device: "Device"34 case .battery: "Battery & Performance"35 case .reports: "Reports"36 case .actions: "Actions"37 case .settings: "Settings"38 }39 }4041 var systemImage: String {42 switch self {43 case .dashboard: "circle.hexagongrid"44 case .securityAudit: "checkmark.shield"45 case .checklist: "checklist"46 case .privacy: "hand.raised"47 case .investigations: "magnifyingglass"48 case .storage: "internaldrive"49 case .photoCleanup: "photo.stack"50 case .fileCleanup: "folder.badge.minus"51 case .linkAnalyzer: "link"52 case .fileScanner: "doc.text.magnifyingglass"53 case .network: "network"54 case .device: "iphone"55 case .battery: "battery.75percent"56 case .reports: "doc.richtext"57 case .actions: "point.3.connected.trianglepath.dotted"58 case .settings: "gearshape"59 }60 }6162 /// The iPhone tab a destination belongs to.63 var tab: AppTab {64 switch self {65 case .dashboard: .overview66 case .securityAudit, .checklist, .privacy, .investigations: .security67 case .storage, .photoCleanup, .fileCleanup: .storage68 case .linkAnalyzer, .fileScanner, .network, .device, .battery, .actions: .tools69 case .reports, .settings: .reports70 }71 }72}7374enum AppTab: String, Hashable, CaseIterable, Identifiable {75 case overview, security, storage, tools, reports76 var id: String { rawValue }7778 /// The screen at the root of the tab. The Tools tab opens on a hub that is not a destination.79 var root: Destination? {80 switch self {81 case .overview: .dashboard82 case .security: .securityAudit83 case .storage: .storage84 case .tools: nil85 case .reports: .reports86 }87 }8889 var title: LocalizedStringKey {90 switch self {91 case .overview: "Overview"92 case .security: "Security"93 case .storage: "Storage"94 case .tools: "Tools"95 case .reports: "Reports"96 }97 }9899 var systemImage: String {100 switch self {101 case .overview: "circle.hexagongrid"102 case .security: "checkmark.shield"103 case .storage: "internaldrive"104 case .tools: "wrench.and.screwdriver"105 case .reports: "doc.richtext"106 }107 }108}109110/// A value pushed on a navigation stack.111enum Route: Hashable {112 case destination(Destination)113 case investigation(Symptom)114 case report(UUID)115}116117@Observable final class Router {118 var tab: AppTab = .overview119 var paths: [AppTab: [Route]] = [:]120 /// iPad sidebar selection.121 var sidebar: Destination? = .dashboard122 var sidebarPath: [Route] = []123 /// A link handed to the app (URL scheme, share) waiting for the link analyser.124 var pendingLink: String?125 /// A file handed to the app ("Open in ORIX Secure") waiting for the file scanner.126 var pendingFile: URL?127 /// A folder waiting for file cleanup (used by UI tests; users pick folders in the system picker).128 var pendingFolder: URL?129130 func path(for tab: AppTab) -> Binding<[Route]> {131 Binding(get: { self.paths[tab] ?? [] }, set: { self.paths[tab] = $0 })132 }133134 /// Shows a top-level screen in whichever layout is active.135 func open(_ destination: Destination) {136 sidebar = destination137 sidebarPath = []138 tab = destination.tab139 paths[destination.tab] = destination == destination.tab.root ? [] : [.destination(destination)]140 }141142 /// Pushes a detail route on the current stack of both layouts.143 func push(_ route: Route) {144 sidebarPath.append(route)145 paths[tab, default: []].append(route)146 }147}148