SPB Git

Repository Public License

ORIXAudioApp.swift 6.3 KB 142 lines swift

1//2//  ORIX Audio3//  File: ORIXAudio/App/ORIXAudioApp.swift4//  Description: App entry point: model container, root navigation (tabs on iPhone, sidebar on iPad), lock overlay, file opening.5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//9import SwiftData10import SwiftUI1112@main13struct ORIXAudioApp: App {14    @State private var model = AppModel(inMemory: ProcessInfo.processInfo.arguments.contains("-ORIXUITesting"))15    @Environment(\.scenePhase) private var scenePhase1617    var body: some Scene {18        WindowGroup {19            RootView()20                .environment(model)21                .environment(model.settings)22                .modelContainer(model.container)23                .preferredColorScheme(model.settings.appearance.colorScheme)24                .tint(ORIX.Palette.cyan)25                .onOpenURL { url in Task { await model.importFiles([url]) } }26                .onChange(of: scenePhase) { _, phase in27                    if phase == .background { model.lockIfNeeded() }28                    if phase == .active { model.refreshRecoverable() }29                }30        }31    }32}3334enum AppSection: String, CaseIterable, Identifiable {35    case record, library, actions, settings36    var id: String { rawValue }37    var title: LocalizedStringKey {38        switch self { case .record: "Record"; case .library: "Library"; case .actions: "Actions"; case .settings: "Settings" }39    }40    var symbol: String {41        switch self { case .record: "record.circle"; case .library: "waveform"; case .actions: "bolt.fill"; case .settings: "gearshape" }42    }43}4445struct RootView: View {46    @Environment(AppModel.self) private var model47    @Environment(AppSettings.self) private var settings48    @State private var section: AppSection = .record49    @State private var libraryPath: [UUID] = []5051    var body: some View {52        TabView(selection: $section) {53            Tab(AppSection.record.title, systemImage: AppSection.record.symbol, value: AppSection.record) {54                NavigationStack { RecorderView() }55            }56            Tab(AppSection.library.title, systemImage: AppSection.library.symbol, value: AppSection.library) {57                LibraryRootView(path: $libraryPath)58            }59            Tab(AppSection.actions.title, systemImage: AppSection.actions.symbol, value: AppSection.actions) {60                NavigationStack { ActionsView() }61            }62            Tab(AppSection.settings.title, systemImage: AppSection.settings.symbol, value: AppSection.settings) {63                NavigationStack { SettingsView() }64            }65        }66        .tabViewStyle(.sidebarAdaptable)67        .onChange(of: model.pendingOpen) { _, id in68            guard let id else { return }69            section = .library70            libraryPath = [id]71            model.pendingOpen = nil72        }73        .overlay { if model.isLocked { LockOverlay() } }74        #if DEBUG75        .task {76            if let initial = DebugHooks.initialSection { section = initial }77            await DebugHooks.run(model: model)78        }79        #endif80        .sheet(isPresented: Binding(get: { !settings.hasSeenWelcome }, set: { if !$0 { settings.hasSeenWelcome = true } })) { WelcomeView() }81        .alert("Import", isPresented: Binding(get: { model.importError != nil }, set: { if !$0 { model.importError = nil } })) {82            Button("OK", role: .cancel) {}83        } message: { Text(model.importError ?? "") }84    }85}8687struct LockOverlay: View {88    @Environment(AppModel.self) private var model89    var body: some View {90        ZStack {91            ORIX.Palette.ink.ignoresSafeArea()92            VStack(spacing: 18) {93                Image("BrandMark").resizable().scaledToFit().frame(width: 96, height: 96).accessibilityHidden(true)94                Text("ORIX Audio is locked").font(.title3.weight(.semibold))95                Button { Task { await model.unlock() } } label: { Label("Unlock", systemImage: "faceid").padding(.horizontal, 12) }96                    .buttonStyle(.borderedProminent)97            }98        }99        .task { await model.unlock() }100    }101}102103struct WelcomeView: View {104    @Environment(AppSettings.self) private var settings105    @Environment(\.dismiss) private var dismiss106    var body: some View {107        ScrollView {108            VStack(alignment: .leading, spacing: 22) {109                Image("BrandMark").resizable().scaledToFit().frame(width: 84, height: 84).frame(maxWidth: .infinity).padding(.top, 28).accessibilityHidden(true)110                VStack(spacing: 6) {111                    Text("ORIX Audio").font(.largeTitle.weight(.bold))112                    Text("Hear Everything. Understand More.").font(.headline).foregroundStyle(ORIX.Palette.textSecondary)113                }.frame(maxWidth: .infinity)114                WelcomeRow(symbol: "lock.shield.fill", title: "Private by design", text: "No account. Recordings, transcripts and notes stay on this device. Nothing is uploaded.")115                WelcomeRow(symbol: "waveform.path.ecg", title: "Real measurements", text: "Every waveform, spectrum and number is computed from the audio itself.")116                WelcomeRow(symbol: "iphone.gen3.radiowaves.left.and.right", title: "Keeps recording when locked", text: "Recording continues with the screen off. The Lock Screen shows the recording in progress.")117                WelcomeRow(symbol: "person.2.wave.2.fill", title: "Record responsibly", text: "Laws on recording conversations vary. Tell people they are being recorded and get consent where it is required.")118                Button { settings.hasSeenWelcome = true; dismiss() } label: { Text("Continue").font(.headline).frame(maxWidth: .infinity).padding(.vertical, 6) }119                    .buttonStyle(.borderedProminent).accessibilityIdentifier("welcomeContinue")120            }121            .padding(24)122        }123        .orixScreenBackground()124        .interactiveDismissDisabled()125    }126}127128private struct WelcomeRow: View {129    let symbol: String130    let title: LocalizedStringKey131    let text: LocalizedStringKey132    var body: some View {133        HStack(alignment: .top, spacing: 14) {134            Image(systemName: symbol).font(.title2).foregroundStyle(ORIX.brandGradient).frame(width: 36).accessibilityHidden(true)135            VStack(alignment: .leading, spacing: 3) {136                Text(title).font(.headline)137                Text(text).font(.subheadline).foregroundStyle(ORIX.Palette.textSecondary)138            }139        }140    }141}142
Files main
Menu

Theme