06/22 Add Check for Update button in Settings

This commit is contained in:
Nguyen Ngo
2026-06-22 10:36:07 -04:00
parent a57d6f02ba
commit 6c48a38743
3 changed files with 174 additions and 0 deletions
+24
View File
@@ -1,10 +1,12 @@
// ContentView.swift
import SwiftUI
import UIKit
struct ContentView: View {
@EnvironmentObject private var auth: AuthManager
@EnvironmentObject private var sync: SyncManager
@StateObject private var updateChecker = UpdateChecker.shared
var body: some View {
Group {
@@ -33,6 +35,28 @@ struct ContentView: View {
if SyncManager.shared.isOnline && AuthManager.shared.isAuthenticated {
await SyncManager.shared.triggerSync()
}
// 4. Check the App Store for a newer version. Independent of auth
// runs even on the login screen so unauthenticated devices still
// get prompted. Throttled internally to once per 24h; silent on
// any failure (offline, parse error, etc.) so it never disrupts
// normal app use.
await updateChecker.checkForUpdate()
}
.alert("Update Available", isPresented: $updateChecker.updateAvailable) {
Button("Update") {
if let url = updateChecker.appStoreURL {
UIApplication.shared.open(url)
}
}
Button("Later", role: .cancel) {
updateChecker.dismissForNow()
}
} message: {
if let version = updateChecker.latestVersion {
Text("Version \(version) is available on the App Store. Update now for the latest fixes and features.")
} else {
Text("A new version is available on the App Store.")
}
}
}
}