-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlusApp.swift
More file actions
53 lines (43 loc) · 1.45 KB
/
PlusApp.swift
File metadata and controls
53 lines (43 loc) · 1.45 KB
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
46
47
48
49
50
51
52
53
//
// PlusApp.swift
//
// Copyright 2023 OpenAlloc LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
import os
import SwiftUI
import TrackerLib
import TrackerUI
import TroutLib
import TroutUI
@main
struct Plus_App: App {
@Environment(\.scenePhase) var scenePhase
// MARK: - Locals
private let coreDataStack = CoreDataStack(isCloud: true)
@AppStorage(colorSchemeModeKey) var colorSchemeMode: ColorSchemeMode = .automatic
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!,
category: "App")
// MARK: - Scene
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.managedObjectContext, coreDataStack.container.viewContext)
.environmentObject(coreDataStack)
.preferredColorScheme(colorSchemeMode.colorScheme)
}
.onChange(of: scenePhase) { _ in
// save if transitioning to inactive or background
guard scenePhase == .inactive || scenePhase == .background else { return }
// and changes are pending
do {
try coreDataStack.container.viewContext.save()
} catch {
logger.error("\(#function): \(error.localizedDescription)")
}
}
}
}