Initial scaffold: context-aware notes app for iOS + macOS
XcodeGen project (Notes / NotesMac / NotesTests), Swift 6 strict concurrency, iCloud-document storage via IndieSync with a SwiftData cache, automatic capture context (location, place, time zone, device) on every note, context-based relevance ranking with a 'Right here, right now' shelf, tags, search, and the square.and.pencil-on-red app icon.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import SwiftData
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct NotesApp: App {
|
||||
@State private var appServices: AppServices?
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
Group {
|
||||
if let appServices {
|
||||
ContentView()
|
||||
.modelContainer(appServices.modelContainer)
|
||||
.environment(appServices.syncEngine)
|
||||
.environment(appServices.contextService)
|
||||
} else {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
.task {
|
||||
if appServices == nil {
|
||||
let services = await AppServices()
|
||||
appServices = services
|
||||
await services.startDeferredServices()
|
||||
}
|
||||
}
|
||||
.onChange(of: scenePhase) { _, phase in
|
||||
guard phase == .active, let appServices else { return }
|
||||
let syncEngine = appServices.syncEngine
|
||||
let contextService = appServices.contextService
|
||||
Task {
|
||||
// Fresh context whenever the user comes back to the app —
|
||||
// recall ranking should reflect where they are right now.
|
||||
await contextService.refresh()
|
||||
}
|
||||
Task {
|
||||
switch syncEngine.iCloudStatus {
|
||||
case .unavailable:
|
||||
// The user typically fixes iCloud in Settings and
|
||||
// switches straight back — retry on foreground.
|
||||
await syncEngine.connect()
|
||||
case .available:
|
||||
// Pull in records that synced down (and drop ones
|
||||
// deleted elsewhere) while the app was backgrounded.
|
||||
await syncEngine.reconcile()
|
||||
case .checking:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if os(macOS)
|
||||
.defaultSize(width: 900, height: 700)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user