refactor: Check server reachability on app resume instead of app start

- Move server check from init to onAppResume() in AppViewModel
- Add scenePhase observer in readeckApp
- Check only when app becomes active (.active phase)
- Respects 30s cache - won't call API if recently checked
This commit is contained in:
Ilyas Hallak 2025-10-19 11:08:13 +02:00
parent e5334d456d
commit fde1140f24
2 changed files with 13 additions and 1 deletions

View File

@ -24,7 +24,6 @@ class AppViewModel: ObservableObject {
Task {
await loadSetupStatus()
await checkServerReachability()
}
}
@ -70,6 +69,11 @@ class AppViewModel: ObservableObject {
hasFinishedSetup = settingsRepository.hasFinishedSetup
}
@MainActor
func onAppResume() async {
await checkServerReachability()
}
@MainActor
private func checkServerReachability() async {
isServerReachable = await checkServerReachabilityUseCase.execute()

View File

@ -12,6 +12,7 @@ import netfox
struct readeckApp: App {
@StateObject private var appViewModel = AppViewModel()
@StateObject private var appSettings = AppSettings()
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
@ -38,6 +39,13 @@ struct readeckApp: App {
await loadAppSettings()
}
}
.onChange(of: scenePhase) { oldPhase, newPhase in
if newPhase == .active {
Task {
await appViewModel.onAppResume()
}
}
}
}
}