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>
74 lines
2.5 KiB
Swift
74 lines
2.5 KiB
Swift
import ManaAuthUI
|
|
import ManaCore
|
|
import SwiftData
|
|
import SwiftUI
|
|
import WidgetKit
|
|
|
|
@main
|
|
struct ZitareNativeApp: App {
|
|
@State private var auth: AuthClient
|
|
@State private var authGate: ManaAuthGate
|
|
@State private var submissionQueue: SubmissionQueue
|
|
private let snapshotContainer: ModelContainer?
|
|
|
|
init() {
|
|
let auth = AuthClient(config: AppConfig.manaAppConfig)
|
|
auth.bootstrap()
|
|
_auth = State(initialValue: auth)
|
|
_authGate = State(initialValue: ManaAuthGate(auth: auth))
|
|
do {
|
|
snapshotContainer = try SnapshotContainer.make()
|
|
} catch {
|
|
Log.snapshot.error(
|
|
"SnapshotContainer init fehlgeschlagen: \(String(describing: error), privacy: .public)"
|
|
)
|
|
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)"
|
|
)
|
|
}
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
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)
|
|
await sync.tryRefresh()
|
|
// Widget-Timeline neu erstellen lassen, sodass der nächste
|
|
// Render-Pass den frischen Snapshot sieht.
|
|
WidgetCenter.shared.reloadAllTimelines()
|
|
}
|
|
}
|