Files
workouts/Workouts/WorkoutsApp.swift
T
rzen 653cc65e0e Integrate IndieBackup for snapshot backup and restore
Adds a local ZIP backup/restore of the iCloud document tree via the
IndieBackup package, surfaced in Settings with retention controls. A
restore suspends the sync observer, mirrors the files, then rebuilds the
SwiftData cache; opening a shared .workoutsbackup file restores it. The
engine exposes the container Documents root and a restore lifecycle
(isRestoring guards a concurrent connect), and the backup file type is
registered for open-in-place.

Claude-Session: https://claude.ai/code/session_01HJDQQDA9QdP8zByg43H5v3
2026-07-08 08:03:30 -04:00

53 lines
1.7 KiB
Swift

//
// WorkoutsApp.swift
// Workouts
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
import SwiftData
import UIKit
@main
struct WorkoutsApp: App {
@State private var services = AppServices()
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
#if DEBUG
if ScreenshotSeed.isActive {
ScreenshotRootView(services: services)
} else {
root
}
#else
root
#endif
}
// Keep the screen lit for the whole app, not just while logging — the phone is
// often propped up across the room during a workout. iOS clears this flag when
// the app is backgrounded, so re-assert it each time the scene becomes active.
.onChange(of: scenePhase, initial: true) { _, phase in
UIApplication.shared.isIdleTimerDisabled = (phase == .active)
}
}
private var root: some View {
RootGateView()
.environment(services)
.environment(services.syncEngine)
.environment(services.liveRunState)
.modelContainer(services.container)
.task { await services.bootstrap() }
// Tap a shared ".workoutsbackup" file (Files, AirDrop, share sheet) to
// restore it. The controller stops the sync observer for the restore and
// rebuilds the cache afterward (see AppBackupConfiguration).
.onOpenURL { url in
guard url.pathExtension == "workoutsbackup" else { return }
Task { try? await services.backupController.restoreBackup(from: url) }
}
}
}