summaryrefslogtreecommitdiff
path: root/WaterfallFile_UI/WaterfallFile_UIApp.swift
blob: be9f25ad7ed97adb068806f04ba22955484308a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
//  WaterfallFile_UIApp.swift
//  WaterfallFile_UI
//
//  Created by Jacky Jack on 23/12/2024.
//

import SwiftUI
import SwiftData

@main
struct WaterfallFile_UIApp: App {
    
    let fileSpectrum = FileSpectrum("rtlsdr_99.5M_m.cu8")
    
    @Environment(\.scenePhase) private var scenePhase
    
    var sharedModelContainer: ModelContainer = {
        let schema = Schema([
            Item.self,
        ])
        let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)

        do {
            return try ModelContainer(for: schema, configurations: [modelConfiguration])
        } catch {
            fatalError("Could not create ModelContainer: \(error)")
        }
    }()

    var body: some Scene {
        WindowGroup {
            ContentView()
            .environmentObject(fileSpectrum)
            .onChange(of: scenePhase) { phase in
                if phase == .active {
                    Task(priority: .userInitiated) {
                        fileSpectrum.startRunning()
                    }
                }
            }
        }
        .modelContainer(sharedModelContainer)
    }
}