-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBodiesApp.swift
45 lines (40 loc) · 1.34 KB
/
BodiesApp.swift
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
import SwiftUI
@main
struct BodiesApp: App {
// Bootstrap the database in the "Application Support" folder.
// "overwrite" can be used during development to get a clean database on
// each run.
#if DEBUG
let database =
try! BodiesDB.bootstrap(into: .cachesDirectory, overwrite: true)
#else
let database = try! BodiesDB.bootstrap(into: .cachesDirectory)
#endif
init() {
// Check whether a migration is necessary.
let schemaVersion =
try! database.get(pragma: "user_version", as: Int.self)
if schemaVersion != BodiesDB.userVersion {
try! database.fetch("UPDATE") { _, _ in }
print("Dumping cache, the version is outdated.")
_ = try! BodiesDB.bootstrap(overwrite: true)
}
}
var body: some Scene {
WindowGroup {
#if os(macOS)
ContentView(database: database)
.frame(width: 440) // just fix it
.navigationTitle("Solar Bodies")
#else // iOS
NavigationView { // just for the visual styling
ContentView(database: database)
.navigationTitle("Solar Bodies")
}
#endif
}
#if os(macOS)
.windowStyle(.titleBar)
#endif
}
}