SPB Git

Repository Public

SPKeyboardApp.swift 8.9 KB 244 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : SP Keyboard9// File             : App/SPKeyboardApp.swift10// Description      : Entry point of the configuration app: five tabs (Accueil,11//                    Theme Studio, SP AI, Typing Lab, Plus), no account and no12//                    sign-in. Settings are re-read whenever the app becomes13//                    active.14// Module           : App15// Repository       : https://git.spboucher.ai/sp-keyboard16// Created          : 2026-12-0117// Last Modified    : 2026-12-0118//19// =============================================================================20// AUTHOR & PROFESSIONAL AFFILIATION21// =============================================================================22//23// Author           : Simon-Pierre Boucher24// Position         : Professor of Finance25// Institution      : Université du Québec en Outaouais (UQO)26// Department       : Département des sciences administratives27// Organization     : SP Boucher28//29// Website          : https://spboucher.ai30// Git              : https://git.spboucher.ai31//32// =============================================================================33// OFFICIAL CONTACT DIRECTORY34// =============================================================================35//36// General          : info@spboucher.ai37// Professional     : contact@spboucher.ai38// Direct           : simon@spboucher.ai39// Research         : research@spboucher.ai40// Development      : dev@spboucher.ai41// Support          : support@spboucher.ai42// Security/Admin   : admin@spboucher.ai43// Notifications    : notifications@spboucher.ai44//45// Preferred Contact: support@spboucher.ai46//47// =============================================================================48// COPYRIGHT & INTELLECTUAL PROPERTY49// =============================================================================50//51// Copyright (c) 202652// Simon-Pierre Boucher53//54// All rights reserved where applicable.55//56// This file is governed by the applicable project license,57// copyright notices, institutional agreements and relevant law.58//59// Unless expressly authorized by the applicable license or60// rights holder, copying, redistribution, sublicensing,61// publication and commercial exploitation are not permitted.62//63// Existing third-party rights and notices remain unaffected.64//65// =============================================================================66// CONFIDENTIALITY & SECURITY67// =============================================================================68//69// Classification   : Public70// Distribution     : Public repository; use is governed by the project license71// Security Contact : admin@spboucher.ai72//73// Access to this source does not independently grant permission74// to redistribute or disclose confidential materials.75//76// Do not embed credentials, private keys, access tokens,77// certificates or confidential personal information.78//79// =============================================================================80// LICENSE & MAINTENANCE81// =============================================================================82//83// License          : None specified (no license file in this repository)84// Maintainer       : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import SwiftUI92import KeyboardCore93import ThemeEngine9495@main96struct SPKeyboardApp: App {97    @State private var model: AppModel98    @State private var router: AppRouter99100    init() {101        let options = LaunchOptions.current102        #if DEBUG103        let model = options.inMemory ? AppModel.inMemory() : AppModel.live()104        #else105        let model = AppModel.live()106        #endif107        _model = State(initialValue: model)108        _router = State(initialValue: AppRouter(options: options, model: model))109    }110111    var body: some Scene {112        WindowGroup {113            RootView()114                .environment(model)115                .environment(router)116                .tint(Palette.violet)117        }118    }119}120121enum AppTab: Hashable {122    case home, themes, ai, typing, more123}124125enum MoreDestination: Hashable {126    case dictionary, diagnostics, privacy, help127}128129/// Navigation state, so a launch option or a status row can open any screen.130@MainActor131@Observable132final class AppRouter {133    var tab: AppTab = .home134    var themePath: [String] = []135    var morePath: [MoreDestination] = []136    let options: LaunchOptions137138    init(options: LaunchOptions, model: AppModel) {139        self.options = options140        switch options.screen {141        case nil, .home: tab = .home142        case .themes: tab = .themes143        case .editor:144            tab = .themes145            let source = options.themeID.flatMap { model.library.theme(id: $0) } ?? model.library.active146            if source.isBuiltIn {147                if let copy = model.duplicateTheme(source) { themePath = [copy.id] }148            } else {149                themePath = [source.id]150            }151        case .ai: tab = .ai152        case .typing: tab = .typing153        case .dictionary: open(.dictionary)154        case .diagnostics: open(.diagnostics)155        case .privacy: open(.privacy)156        case .help: open(.help)157        }158        if options.screen != .editor, let id = options.themeID { model.activateTheme(id: id) }159    }160161    func open(_ destination: MoreDestination) {162        tab = .more163        morePath = [destination]164    }165}166167struct RootView: View {168    @Environment(AppModel.self) private var model169    @Environment(AppRouter.self) private var router170    @Environment(\.scenePhase) private var scenePhase171172    var body: some View {173        @Bindable var router = router174        TabView(selection: $router.tab) {175            NavigationStack { HomeView() }176                .tabItem { Label("Accueil", systemImage: "house") }177                .tag(AppTab.home)178            NavigationStack(path: $router.themePath) {179                ThemeStudioView()180                    .navigationDestination(for: String.self) { ThemeEditorView(themeID: $0) }181            }182            .tabItem { Label("Thèmes", systemImage: "paintpalette") }183            .tag(AppTab.themes)184            NavigationStack { AIConfigView() }185                .tabItem { Label("SP AI", systemImage: "sparkle") }186                .tag(AppTab.ai)187            NavigationStack { TypingLabView() }188                .tabItem { Label("Frappe", systemImage: "keyboard") }189                .tag(AppTab.typing)190            NavigationStack(path: $router.morePath) {191                MoreView()192                    .navigationDestination(for: MoreDestination.self) { destination in193                        switch destination {194                        case .dictionary: DictionaryView()195                        case .diagnostics: DiagnosticsView()196                        case .privacy: PrivacyView()197                        case .help: HelpView()198                        }199                    }200            }201            .tabItem { Label("Plus", systemImage: "ellipsis.circle") }202            .tag(AppTab.more)203        }204        .onChange(of: scenePhase) { _, phase in205            if phase == .active { model.reload() }206        }207    }208}209210struct MoreView: View {211    @Environment(AppModel.self) private var model212213    var body: some View {214        List {215            Section {216                NavigationLink(value: MoreDestination.dictionary) {217                    Label("Dictionnaire et snippets", systemImage: "character.book.closed")218                }219                .accessibilityIdentifier("more.dictionary")220                NavigationLink(value: MoreDestination.diagnostics) {221                    Label("Diagnostics", systemImage: "stethoscope")222                }223                .accessibilityIdentifier("more.diagnostics")224            }225            Section {226                NavigationLink(value: MoreDestination.privacy) {227                    Label("Confidentialité", systemImage: "hand.raised")228                }229                .accessibilityIdentifier("more.privacy")230                NavigationLink(value: MoreDestination.help) {231                    Label("Aide et installation", systemImage: "questionmark.circle")232                }233                .accessibilityIdentifier("more.help")234            }235            Section {236                LabeledContent("Version", value: "\(model.appVersion) (\(model.appBuild))")237            } footer: {238                Text("SP Keyboard est un outil personnel : aucun compte, aucune publicité, aucune télémétrie.")239            }240        }241        .navigationTitle("Plus")242    }243}244
Files main
Menu

Theme