SPB Git

Repository Public License

RootView.swift 7.6 KB 179 lines swift

1// ORIX Secure2// File: App/Sources/Core/RootView.swift3// Description: Root layout: five tabs on iPhone, a grouped sidebar with a detail column on iPad. Both share the same screens.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import ORIXDesign8import ORIXSecureEngines9import SwiftUI1011struct RootView: View {12    @Environment(\.horizontalSizeClass) private var sizeClass13    @Environment(AppSettings.self) private var settings1415    var body: some View {16        Group {17            if sizeClass == .regular { SidebarLayout() } else { TabLayout() }18        }19        .sheet(isPresented: Binding(get: { !settings.hasSeenWelcome }, set: { if !$0 { settings.hasSeenWelcome = true } })) {20            WelcomeView()21        }22    }23}2425/// Maps a destination to its screen.26struct DestinationView: View {27    let destination: Destination28    var body: some View {29        switch destination {30        case .dashboard: DashboardView()31        case .securityAudit: SecurityAuditView()32        case .checklist: ChecklistView(domain: .security)33        case .privacy: PrivacyAuditView()34        case .investigations: InvestigationsView()35        case .storage: StorageView()36        case .photoCleanup: PhotoCleanupView()37        case .fileCleanup: FileCleanupView()38        case .linkAnalyzer: LinkAnalyzerView()39        case .fileScanner: FileScannerView()40        case .network: NetworkLabView()41        case .device: DeviceView()42        case .battery: BatteryView()43        case .reports: ReportsView()44        case .actions: ActionsView()45        case .settings: SettingsView()46        }47    }48}4950private struct RouteDestinations: ViewModifier {51    func body(content: Content) -> some View {52        content.navigationDestination(for: Route.self) { route in53            switch route {54            case .destination(let destination): DestinationView(destination: destination)55            case .investigation(let symptom): InvestigationFlowView(symptom: symptom)56            case .report(let id): ReportDetailView(reportID: id)57            }58        }59    }60}6162private struct TabLayout: View {63    @Environment(Router.self) private var router6465    var body: some View {66        @Bindable var router = router67        TabView(selection: $router.tab) {68            ForEach(AppTab.allCases) { tab in69                Tab(tab.title, systemImage: tab.systemImage, value: tab) {70                    NavigationStack(path: router.path(for: tab)) {71                        Group {72                            if let root = tab.root { DestinationView(destination: root) } else { ToolsHubView() }73                        }74                        .modifier(RouteDestinations())75                    }76                }77                .accessibilityIdentifier("tab." + tab.rawValue)78            }79        }80    }81}8283private struct SidebarLayout: View {84    @Environment(Router.self) private var router8586    private let groups: [(LocalizedStringKey, [Destination])] = [87        ("", [.dashboard]),88        ("Security", [.securityAudit, .checklist, .privacy, .investigations]),89        ("Storage", [.storage, .photoCleanup, .fileCleanup]),90        ("Tools", [.linkAnalyzer, .fileScanner, .network, .device, .battery, .actions]),91        ("Results", [.reports, .settings]),92    ]9394    var body: some View {95        @Bindable var router = router96        NavigationSplitView {97            List(selection: $router.sidebar) {98                ForEach(Array(groups.enumerated()), id: \.offset) { _, group in99                    Section(group.0) {100                        ForEach(group.1) { destination in101                            Label(destination.title, systemImage: destination.systemImage)102                                .tag(destination)103                                .accessibilityIdentifier("sidebar." + destination.rawValue)104                        }105                    }106                }107            }108            .navigationTitle("ORIX Secure")109            .onChange(of: router.sidebar) { _, _ in router.sidebarPath = [] }110        } detail: {111            NavigationStack(path: $router.sidebarPath) {112                DestinationView(destination: router.sidebar ?? .dashboard)113                    .modifier(RouteDestinations())114            }115            .id(router.sidebar)116        }117    }118}119120/// The Tools tab on iPhone.121struct ToolsHubView: View {122    var body: some View {123        ScreenScroll {124            Text("Each tool runs on this device and shows the evidence behind its results.")125                .font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary)126            NavigationTile(destination: .linkAnalyzer, detail: String(localized: "Inspect a link's structure without opening it"))127            NavigationTile(destination: .fileScanner, detail: String(localized: "Type, hash and structure of a file you choose"))128            NavigationTile(destination: .network, detail: String(localized: "Connectivity, DNS, latency, certificates, Wi-Fi"))129            NavigationTile(destination: .device, detail: String(localized: "What iOS lets an app measure, and what it does not"))130            NavigationTile(destination: .battery, detail: String(localized: "Readings and guidance — no fake boosters"))131            NavigationTile(destination: .actions, detail: String(localized: "Reusable diagnostic workflows"))132        }133        .navigationTitle("Tools")134        .accessibilityIdentifier("tools.hub")135    }136}137138/// First launch: what the app is, and what no app can be.139struct WelcomeView: View {140    @Environment(\.dismiss) private var dismiss141    @Environment(AppSettings.self) private var settings142143    var body: some View {144        ScrollView {145            VStack(alignment: .leading, spacing: ORIX.Space.lg) {146                ORIXMark().frame(width: 84, height: 84).frame(maxWidth: .infinity)147                VStack(spacing: ORIX.Space.xs) {148                    Text("ORIX Secure").font(.orixDisplay).foregroundStyle(ORIX.Palette.textPrimary)149                    Text("Know your device. Protect what matters.").font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary)150                }151                .frame(maxWidth: .infinity)152                point("checkmark.seal", "Real checks only", "Every result names the evidence behind it and how it was obtained.")153                point("eye.slash", "Honest about limits", "No app can scan an iPhone for malware. ORIX Secure says what it cannot see instead of pretending.")154                point("person.crop.circle.badge.checkmark", "You confirm what apps cannot read", "Most security settings are invisible to apps. ORIX Secure shows where they are and records your answer as yours.")155                point("lock.shield", "Private by construction", "No account, no ads, no analytics. Results stay on this device unless you export them.")156                Button { settings.hasSeenWelcome = true; dismiss() } label: { Text("Get Started") }157                    .buttonStyle(.orixPrimary)158                    .accessibilityIdentifier("welcome.start")159            }160            .padding(ORIX.Space.xl)161            .frame(maxWidth: 560)162            .frame(maxWidth: .infinity)163        }164        .background(ORIX.Palette.canvas.ignoresSafeArea())165        .interactiveDismissDisabled()166    }167168    private func point(_ symbol: String, _ title: LocalizedStringKey, _ detail: LocalizedStringKey) -> some View {169        HStack(alignment: .top, spacing: ORIX.Space.sm) {170            ORIXGlyph(symbol, size: 40)171            VStack(alignment: .leading, spacing: 2) {172                Text(title).font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary)173                Text(detail).font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary)174            }175        }176        .accessibilityElement(children: .combine)177    }178}179
Files main
Menu

Theme