Repository Public
1// SP Notes iOS2// File: App/StoreFailureScreen.swift3// Description: The blocking screen shown when the local database cannot be opened or migrated (SPNotesCore 2.0 typed result).4// It explains what happened, says that the notes were not modified, where the pre-migration copy is, and offers5// to try again when that can help. The app never continues with an empty store in place of the user's file.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import SPNotesCore10import SPNotesDesign11import SwiftUI1213/// What the failure screen shows, derived from the typed error (pure, tested).14struct StoreFailure: Equatable {15 var title: String16 var message: String17 /// Technical line for the support (never the only explanation).18 var detail: String19 var canRetry: Bool20 var backupName: String?21 var symbol: String2223 init(_ error: Error) {24 let typed = (error as? StoreOpenError) ?? .other(error.localizedDescription)25 message = typed.userMessage26 detail = typed.description27 canRetry = typed.isTransient || { if case .migrationFailed = typed { return true } else { return false } }()28 backupName = typed.backupURL?.lastPathComponent29 switch typed {30 case .newerSchema:31 title = String(localized: "Mise à jour de l’application requise"); symbol = "arrow.down.app"32 case .corrupt:33 title = String(localized: "Base locale endommagée"); symbol = "externaldrive.badge.exclamationmark"34 case .locked:35 title = String(localized: "Base locale occupée"); symbol = "lock.rectangle.stack"36 case .storage, .backupFailed:37 title = String(localized: "Espace ou accès insuffisant"); symbol = "internaldrive"38 case .migrationFailed:39 title = String(localized: "Mise à jour de la base annulée"); symbol = "arrow.uturn.backward.circle"40 case .outdatedReadOnly, .other:41 title = String(localized: "SP Notes ne peut pas ouvrir sa base locale"); symbol = "exclamationmark.triangle"42 }43 }44}4546struct StoreFailureScreen: View {47 let failure: StoreFailure48 var retry: () -> Void4950 var body: some View {51 ScrollView {52 VStack(spacing: NVSpace.lg) {53 Image(systemName: failure.symbol).font(.system(size: 44, weight: .light)).foregroundStyle(NVColor.warning).accessibilityHidden(true)54 Text(failure.title).nvFont(.h2).foregroundStyle(NVColor.fg).multilineTextAlignment(.center)55 Text(failure.message).font(.body).foregroundStyle(NVColor.fgMuted).multilineTextAlignment(.center)56 VStack(alignment: .leading, spacing: NVSpace.sm) {57 Label("Aucune note n’a été effacée : le fichier est resté tel quel sur cet appareil.", systemImage: "checkmark.shield")58 if let backup = failure.backupName {59 Label("Copie de sécurité conservée : \(backup)", systemImage: "doc.on.doc")60 }61 Label("L’application ne démarre pas avec une bibliothèque vide à la place de vos notes.", systemImage: "hand.raised")62 }63 .font(.subheadline).foregroundStyle(NVColor.fg)64 .padding(NVSpace.lg)65 .frame(maxWidth: .infinity, alignment: .leading)66 .nvCard()67 if failure.canRetry {68 Button("Réessayer", action: retry).buttonStyle(PrimaryButtonStyle()).accessibilityIdentifier("store-failure-retry")69 }70 Text(failure.detail).font(.footnote.monospaced()).foregroundStyle(NVColor.fgMuted).multilineTextAlignment(.center).textSelection(.enabled)71 }72 .padding(NVSpace.xl)73 .frame(maxWidth: 520)74 .frame(maxWidth: .infinity)75 }76 .background(NVColor.bg)77 .accessibilityIdentifier("store-failure")78 }79}80