road distance: trigger at launch + foreground, fall back to saved location
Road-distance routing previously only fired once a fresh GPS fix arrived via the location hook/onChange. A returning user on a cold launch waited for that fix, and if onboarding/flag issues kept tracking from starting, distances stayed straight-line. Now: - refreshRoadDistancesIfNeeded() uses the last saved location when the live fix isn't set yet, so it can run immediately. - It's called explicitly on launch (already-onboarded branch), on foreground activation, and on the existing location paths.
This commit is contained in:
@@ -56,14 +56,16 @@ struct ContentView: View {
|
||||
|
||||
/// Kicks off a (throttled) Apple-Maps road-distance recompute for the
|
||||
/// stations around the current fix. The app owns routing — the widget and
|
||||
/// Live Activity only read the cached result.
|
||||
/// Live Activity only read the cached result. Falls back to the last saved
|
||||
/// location so it can run before the first fresh GPS fix arrives.
|
||||
private func refreshRoadDistancesIfNeeded() {
|
||||
guard let location else { return }
|
||||
let origin = location ?? FuelStore.loadLocation()
|
||||
guard let origin else { return }
|
||||
Task {
|
||||
await RoadDistanceService.refreshIfNeeded(
|
||||
stations: stations,
|
||||
lat: location.lat,
|
||||
lng: location.lng
|
||||
lat: origin.lat,
|
||||
lng: origin.lng
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -332,6 +334,10 @@ struct ContentView: View {
|
||||
fuel: alertsFuel, radiusKM: effectiveAlertsRadiusKM)
|
||||
monitor.setEnabled(alertsEnabled)
|
||||
updateLiveActivity()
|
||||
// Compute road distances early (throttled; falls back to the
|
||||
// last saved location) so distance surfaces are road-matched
|
||||
// as soon as stations are available.
|
||||
refreshRoadDistancesIfNeeded()
|
||||
// Refresh only when the cache is stale (twice-a-day policy).
|
||||
// Skipped under the force-* hooks so the banner stays up.
|
||||
#if DEBUG
|
||||
@@ -377,6 +383,7 @@ struct ContentView: View {
|
||||
monitor.update(stations: stations, favourites: refreshedFavourites,
|
||||
fuel: alertsFuel, radiusKM: effectiveAlertsRadiusKM)
|
||||
updateLiveActivity()
|
||||
refreshRoadDistancesIfNeeded()
|
||||
// No network fetch on foreground — pull-to-refresh is the override.
|
||||
} else {
|
||||
locationManager.stopForegroundTracking()
|
||||
|
||||
Reference in New Issue
Block a user