Major update for stability
This commit is contained in:
@@ -5,6 +5,7 @@ import SwiftData
|
||||
@MainActor
|
||||
struct RsyncManagerApp: App {
|
||||
let sharedModelContainer: ModelContainer
|
||||
let startupStorageError: String?
|
||||
@StateObject private var runner: RsyncRunner
|
||||
@StateObject private var automation: BackgroundSyncManager
|
||||
|
||||
@@ -14,20 +15,33 @@ struct RsyncManagerApp: App {
|
||||
SyncRun.self,
|
||||
])
|
||||
let configuration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
|
||||
KeychainStore.delete("defaultSSHPassword")
|
||||
|
||||
do {
|
||||
let container = try ModelContainer(for: schema, configurations: [configuration])
|
||||
sharedModelContainer = container
|
||||
startupStorageError = nil
|
||||
let rsyncRunner = RsyncRunner()
|
||||
_runner = StateObject(wrappedValue: rsyncRunner)
|
||||
_automation = StateObject(wrappedValue: BackgroundSyncManager(modelContext: container.mainContext, runner: rsyncRunner))
|
||||
} catch {
|
||||
fatalError("Could not create ModelContainer: \(error)")
|
||||
let fallbackConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: true)
|
||||
do {
|
||||
let fallback = try ModelContainer(for: schema, configurations: [fallbackConfiguration])
|
||||
sharedModelContainer = fallback
|
||||
startupStorageError = "Rsync Manager could not open its persistent database and is running with temporary in-memory storage for this session. Jobs or history created now will not persist. Original error: \(error.localizedDescription)"
|
||||
let rsyncRunner = RsyncRunner()
|
||||
_runner = StateObject(wrappedValue: rsyncRunner)
|
||||
_automation = StateObject(wrappedValue: BackgroundSyncManager(modelContext: fallback.mainContext, runner: rsyncRunner))
|
||||
} catch {
|
||||
fatalError("Rsync Manager could not initialise persistent or temporary storage: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView()
|
||||
ContentView(startupStorageError: startupStorageError)
|
||||
.frame(minWidth: 1040, minHeight: 680)
|
||||
.environmentObject(runner)
|
||||
.environmentObject(automation)
|
||||
|
||||
Reference in New Issue
Block a user