ζ-3.5: Offline-Submit-Queue mit SwiftData + Auto-Retry
Bei Network-Failure landet der Quote-Draft jetzt in einer persistenten SwiftData-Queue (\`PendingSubmission\`) statt im Error-Banner. Beim nächsten App-Launch ODER beim Wechsel auf scenePhase.active wird der Flush automatisch versucht. Retry-Policy: - 5xx oder Transport-Failure (NSURLErrorDomain) → in Queue, Retry - 4xx mit code (validation_failed, duplicate, unauthorized) → permanenter Fehler, kein Retry (User-Aktion nötig) - Hard-Limit 50 Retries pro Entry, danach pausiert App-Group-Store \`submissions.store\` (parallel zu snapshot.store) im \`group.ev.mana.zitare\`-Container. Fallback auf In-Memory falls Disk-Init scheitert (App-Group noch nicht aktiviert im Apple-Dev-Portal). UI-Pieces: - Pending-Banner zeigt Queue-Tiefe wenn > 0 - Queued-Banner nach erfolgreichem Enqueue - Form-Reset nach Enqueue (User sieht: "weg, kommt nach") - onChange(scenePhase) → Auto-Flush bei Foreground - ZitareNativeApp.task: Flush am Launch Files: - Sources/Core/Submit/PendingSubmissionModel.swift (neu, @Model) - Sources/Core/Submit/SubmissionQueue.swift (neu, @Observable @MainActor) - Sources/App/ZitareNativeApp.swift: Container-Init + environment-Wiring - Sources/Features/Submit/SubmitQuoteView.swift: enqueue + flush + banners iOS + macOS BUILD SUCCEEDED. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ef8364f05d
commit
61927d27a3
4 changed files with 308 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ import WidgetKit
|
|||
struct ZitareNativeApp: App {
|
||||
@State private var auth: AuthClient
|
||||
@State private var authGate: ManaAuthGate
|
||||
@State private var submissionQueue: SubmissionQueue
|
||||
private let snapshotContainer: ModelContainer?
|
||||
|
||||
init() {
|
||||
|
|
@ -23,6 +24,18 @@ struct ZitareNativeApp: App {
|
|||
)
|
||||
snapshotContainer = nil
|
||||
}
|
||||
let pending: ModelContainer
|
||||
do {
|
||||
pending = try PendingSubmissionContainer.make()
|
||||
} catch {
|
||||
Log.app.error(
|
||||
"PendingSubmissionContainer-Disk init fehlgeschlagen, falle auf in-memory zurück: \(String(describing: error), privacy: .public)"
|
||||
)
|
||||
// In-memory-Fallback statt nil. Submissions sind dann nur
|
||||
// für die aktuelle Session persistiert — besser als Crash.
|
||||
pending = try! PendingSubmissionContainer.make(inMemory: true)
|
||||
}
|
||||
_submissionQueue = State(initialValue: SubmissionQueue(container: pending))
|
||||
Log.app.info(
|
||||
"Zitare starting — auth status: \(String(describing: auth.status), privacy: .public)"
|
||||
)
|
||||
|
|
@ -33,13 +46,23 @@ struct ZitareNativeApp: App {
|
|||
RootView()
|
||||
.environment(auth)
|
||||
.environment(authGate)
|
||||
.environment(submissionQueue)
|
||||
.tint(ZitareTheme.primary)
|
||||
.task {
|
||||
await refreshSnapshot()
|
||||
await flushPending()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func flushPending() async {
|
||||
let api = ZitareAPI(auth: auth)
|
||||
let sent = await submissionQueue.tryFlush(api: api)
|
||||
if sent > 0 {
|
||||
Log.app.info("Auto-flushed \(sent) pending submission(s) at launch")
|
||||
}
|
||||
}
|
||||
|
||||
private func refreshSnapshot() async {
|
||||
guard let container = snapshotContainer else { return }
|
||||
let sync = SnapshotSync(container: container)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue