| @@ -10,6 +10,8 @@ import UserNotifications |
| 10 | struct OrgstarMobileApp: App { |
10 | struct OrgstarMobileApp: App { |
| 11 | @UIApplicationDelegateAdaptor private var delegate: AppDelegate |
11 | @UIApplicationDelegateAdaptor private var delegate: AppDelegate |
| 12 | @State private var model = MobileModel.shared |
12 | @State private var model = MobileModel.shared |
| |
13 | /// The app's phase: in the background only when every window is. |
| |
14 | @Environment(\.scenePhase) private var scenePhase |
| 13 | |
15 | |
| 14 | init() { |
16 | init() { |
| 15 | // Debug builds, and runs from Xcode, whose scheme sets ORGSTAR_PERF. |
17 | // Debug builds, and runs from Xcode, whose scheme sets ORGSTAR_PERF. |
| @@ -35,6 +37,10 @@ struct OrgstarMobileApp: App { |
| 35 | ContentUnavailableView("Can't open the index", systemImage: "exclamationmark.triangle", description: Text(model.failure ?? "")) |
37 | ContentUnavailableView("Can't open the index", systemImage: "exclamationmark.triangle", description: Text(model.failure ?? "")) |
| 36 | } |
38 | } |
| 37 | } |
39 | } |
| |
40 | // For the clock's idle time: time working in another window isn't time away. |
| |
41 | .onChange(of: scenePhase) { _, phase in |
| |
42 | if phase == .background { model.clock.wentAway() } |
| |
43 | } |
| 38 | } |
44 | } |
| 39 | } |
45 | } |
| 40 | |
46 | |
| @@ -119,8 +125,6 @@ struct RootView: View { |
| 119 | @State private var hour = 0 |
125 | @State private var hour = 0 |
| 120 | @State private var showingClockReport = false |
126 | @State private var showingClockReport = false |
| 121 | @State private var message: String? |
127 | @State private var message: String? |
| 122 | /// When the app went to the background, for the clock's idle time. |
| |
| 123 | @State private var backgrounded: Date? |
| |
| 124 | @Environment(\.scenePhase) private var scenePhase |
128 | @Environment(\.scenePhase) private var scenePhase |
| 125 | @AppStorage(OnboardingScreen.doneKey) private var onboarded = false |
129 | @AppStorage(OnboardingScreen.doneKey) private var onboarded = false |
| 126 | @State private var onboarding = false |
130 | @State private var onboarding = false |
| @@ -323,16 +327,13 @@ struct RootView: View { |
| 323 | // Unsaved edits are written before the app may be stopped. |
327 | // Unsaved edits are written before the app may be stopped. |
| 324 | if phase == .background { |
328 | if phase == .background { |
| 325 | for path in session.dirtyPaths { _ = session.save(path) } |
329 | for path in session.dirtyPaths { _ = session.save(path) } |
| 326 | backgrounded = Date() |
| |
| 327 | } |
330 | } |
| 328 | // Files and settings synced while away; not every sync tool tells file presenters. |
331 | // Files and settings synced while away; not every sync tool tells file presenters. |
| 329 | guard phase == .active else { return } |
332 | guard phase == .active else { return } |
| 330 | // iOS has no idle time: time away from the app while a clock ran stands in for it. |
333 | // iOS has no idle time: time away from the app while a clock ran stands in for it. |
| 331 | if let left = backgrounded, let since = ClockModel.idleSince( |
334 | if let since = model.clock.cameBack(idleMinutes: OrgPreferences.clockIdleTime()) { |
| 332 | backgrounded: left, now: Date(), running: model.clock.running, idleMinutes: OrgPreferences.clockIdleTime()) { |
| |
| 333 | MobileClock.resolveIdle(since: since, model: model) { message = $0 } |
335 | MobileClock.resolveIdle(since: since, model: model) { message = $0 } |
| 334 | } |
336 | } |
| 335 | backgrounded = nil |
| |
| 336 | takeShared() |
337 | takeShared() |
| 337 | model.reloadConfig() |
338 | model.reloadConfig() |
| 338 | Task { await workspace.refresh() } |
339 | Task { await workspace.refresh() } |