import Foundation import IndieBackup import SwiftData /// Owns all service objects; created asynchronously at launch and injected /// into the SwiftUI environment. @Observable @MainActor final class AppServices { let modelContainer: ModelContainer let syncEngine: SyncEngine let contextService: ContextService let backupController: BackupController init() async { let container = NotesModelContainer.make() self.modelContainer = container let engine = SyncEngine(modelContainer: container) self.syncEngine = engine self.contextService = ContextService() self.backupController = BackupController( configuration: NotesBackupConfiguration(syncEngine: engine) ) } /// The file extension this app owns for backup documents. Used to route /// `onOpenURL` imports to a restore. var backupFileExtension: String { backupController.configuration.backupFileExtension } /// Slow startup work (iCloud container discovery) — runs after the UI is up. func startDeferredServices() async { await syncEngine.connect() } }