SPB Git

Repository Public

HomeView.swift 10.3 KB 221 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : SP Keyboard9// File             : App/Screens/HomeView.swift10// Description      : Accueil: the SP mark, a status list limited to what the11//                    app can really verify (iOS does not tell an app whether12//                    its keyboard is enabled), the Settings guide and two test13//                    areas: a real text field for the installed keyboard, and14//                    the embedded preview keyboard.15// Module           : App16// Repository       : https://git.spboucher.ai/sp-keyboard17// Created          : 2026-12-0118// Last Modified    : 2026-12-0119//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author           : Simon-Pierre Boucher25// Position         : Professor of Finance26// Institution      : Université du Québec en Outaouais (UQO)27// Department       : Département des sciences administratives28// Organization     : SP Boucher29//30// Website          : https://spboucher.ai31// Git              : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General          : info@spboucher.ai38// Professional     : contact@spboucher.ai39// Direct           : simon@spboucher.ai40// Research         : research@spboucher.ai41// Development      : dev@spboucher.ai42// Support          : support@spboucher.ai43// Security/Admin   : admin@spboucher.ai44// Notifications    : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification   : Public71// Distribution     : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License          : None specified (no license file in this repository)85// Maintainer       : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import SwiftUI93import KeyboardCore94import ThemeEngine9596struct HomeView: View {97    @Environment(AppModel.self) private var model98    @Environment(AppRouter.self) private var router99    @Environment(\.openURL) private var openURL100    @State private var realText = ""101    @State private var document = PreviewDocument()102    @FocusState private var realFieldFocused: Bool103104    var body: some View {105        List {106            Section {107                HStack(spacing: 16) {108                    SPLogo(size: 68)109                    VStack(alignment: .leading, spacing: 4) {110                        Text("SP Keyboard").font(.title2.weight(.bold))111                        Text("Clavier personnel, hors ligne par défaut, avec Claude à la demande.")112                            .font(.subheadline)113                            .foregroundStyle(.secondary)114                    }115                }116                .padding(.vertical, 6)117                .accessibilityElement(children: .combine)118            }119120            Section {121                statusRows122            } header: {123                Text("État vérifiable")124            } footer: {125                Text("iOS n'indique pas à une app si son clavier est activé ni si l'accès complet est accordé. Les deux dernières lignes viennent du dernier rapport écrit par le clavier lui-même.")126            }127128            Section("Activer le clavier") {129                guideStep(1, "Ouvrez Réglages → Général → Clavier → Claviers.")130                guideStep(2, "Touchez « Ajouter un clavier… », puis SP Keyboard.")131                guideStep(3, "Facultatif : touchez SP Keyboard puis « Autoriser l'accès complet ». Seuls SP AI, le retour haptique et le partage des réglages en ont besoin.")132                guideStep(4, "Dans Messages, touchez le globe 🌐 pour passer à SP Keyboard.")133                Button {134                    if let url = URL(string: UIApplication.openSettingsURLString) { openURL(url) }135                } label: {136                    Label("Ouvrir les réglages de SP Keyboard", systemImage: "gear")137                }138                .accessibilityIdentifier("home.openSettings")139                Text("Dans les champs de mot de passe et certains champs téléphoniques, iOS revient au clavier système. Certaines apps refusent les claviers tiers. La dictée n'est pas offerte par un clavier tiers.")140                    .font(.footnote)141                    .foregroundStyle(.secondary)142            }143144            Section {145                TextField("Touchez ici, puis le globe pour choisir SP Keyboard", text: $realText, axis: .vertical)146                    .lineLimit(2...5)147                    .focused($realFieldFocused)148                    .accessibilityIdentifier("home.realField")149                if realFieldFocused {150                    Button("Fermer le clavier") { realFieldFocused = false }151                }152            } header: {153                Text("Essai avec le clavier installé")154            } footer: {155                Text("Ce champ utilise le clavier choisi dans iOS. Utilisez un texte fictif.")156            }157158            Section {159                PreviewDocumentText(document: document)160                    .frame(minHeight: 44, alignment: .topLeading)161                KeyboardPreview(theme: model.library.active, settings: model.settings, dictionary: model.dictionary,162                                aiSettings: model.ai, document: document,163                                initialPanel: router.options.panel, initialPage: router.options.page)164                    .listRowInsets(EdgeInsets(top: 6, leading: 6, bottom: 6, trailing: 6))165                Button("Effacer l'aperçu", role: .destructive) { document.reset() }166                    .accessibilityIdentifier("home.clearPreview")167            } header: {168                Text("Aperçu intégré")169            } footer: {170                Text("Le même clavier que l'extension, dessiné dans l'app, avec le thème « \(model.library.active.name) ». Il fonctionne même si le clavier n'est pas encore activé dans Réglages.")171            }172        }173        .navigationTitle("Accueil")174        .navigationBarTitleDisplayMode(.inline)175        .refreshable { model.reload() }176    }177178    @ViewBuilder private var statusRows: some View {179        StatusRow(title: "Conteneur partagé",180                  detail: model.isSharedContainerReachable ? "Accessible : les réglages atteignent le clavier." : "Inaccessible : le clavier utilisera ses valeurs par défaut.",181                  level: model.isSharedContainerReachable ? .good : .warning)182        switch model.keyState {183        case .present(let masked):184            StatusRow(title: "Clé Anthropic", detail: "Présente dans le trousseau (\(masked)).", level: .good)185        case .absent:186            StatusRow(title: "Clé Anthropic", detail: "Aucune clé. SP AI est facultatif ; le reste fonctionne sans.", level: .neutral)187        case .unavailable(let code):188            StatusRow(title: "Clé Anthropic", detail: "Trousseau inaccessible (\(code)).", level: .warning)189        }190        if let selected = model.ai.selectedModel {191            StatusRow(title: "Modèle SP AI", detail: selected.displayName, level: .good)192        } else {193            StatusRow(title: "Modèle SP AI", detail: "Aucun modèle choisi.", level: .neutral)194        }195        if let date = model.metrics.updatedAt {196            StatusRow(title: "Dernier rapport du clavier",197                      detail: "Reçu \(date.formatted(.relative(presentation: .named))).", level: .good)198            if let access = model.metrics.hadFullAccess {199                StatusRow(title: "Accès complet lors de ce rapport", detail: access ? "Accordé." : "Non accordé.", level: access ? .good : .neutral)200            }201        } else {202            StatusRow(title: "Dernier rapport du clavier",203                      detail: "Aucun rapport reçu. Le clavier n'en écrit un que s'il a été utilisé avec l'accès complet.", level: .neutral)204        }205    }206207    private func guideStep(_ number: Int, _ text: String) -> some View {208        HStack(alignment: .firstTextBaseline, spacing: 12) {209            Text("\(number)")210                .font(.footnote.weight(.bold))211                .foregroundStyle(.white)212                .frame(width: 22, height: 22)213                .background(Circle().fill(Color(red: 0.36, green: 0.2, blue: 0.78)))214                .accessibilityHidden(true)215            Text(text).font(.subheadline)216        }217        .accessibilityElement(children: .combine)218        .accessibilityLabel("Étape \(number). \(text)")219    }220}221
Files main
Menu

Theme