suspected locations background refresh

This commit is contained in:
stopflock
2026-06-14 21:40:22 -05:00
parent 0b812bdaea
commit 12ffe92df8
4 changed files with 30 additions and 6 deletions
+2 -1
View File
@@ -2,7 +2,8 @@
"2.10.2": { "2.10.2": {
"content": [ "content": [
"• Added tap and hold gesture on empty map area to add a node at that location", "• Added tap and hold gesture on empty map area to add a node at that location",
"• Added ability to accept direct links to a specific node for callbacks from e.g. FlockHopper" "• Added ability to accept direct links to a specific node for callbacks from e.g. FlockHopper",
"• Fixed app hang during startup when suspected locations database needed updating - refresh now happens in background"
] ]
}, },
"2.10.1": { "2.10.1": {
+3
View File
@@ -250,6 +250,9 @@ class AppState extends ChangeNotifier {
_isInitialized = true; _isInitialized = true;
// Start background refresh of suspected locations if needed (non-blocking)
_suspectedLocationState.initBackgroundRefresh(offlineMode: _settingsState.offlineMode);
// Check for initial deep link after a small delay to let navigation settle // Check for initial deep link after a small delay to let navigation settle
Future.delayed(const Duration(milliseconds: 500), () { Future.delayed(const Duration(milliseconds: 500), () {
DeepLinkService().checkInitialLink(); DeepLinkService().checkInitialLink();
+20 -5
View File
@@ -35,16 +35,31 @@ class SuspectedLocationService {
// Load cache data // Load cache data
await _cache.loadFromStorage(); await _cache.loadFromStorage();
// Only auto-fetch if enabled, data is stale or missing, and we are not offline // Note: Auto-refresh logic moved to initBackgroundRefresh() to avoid blocking app startup
if (_isEnabled && (await _shouldRefresh()) && !offlineMode) { if (_isEnabled && (await _shouldRefresh()) && offlineMode) {
debugPrint('[SuspectedLocationService] Auto-refreshing CSV data on startup (older than $_maxAge or missing)');
await _fetchData();
} else if (_isEnabled && (await _shouldRefresh()) && offlineMode) {
final lastFetch = await _cache.lastFetchTime; final lastFetch = await _cache.lastFetchTime;
debugPrint('[SuspectedLocationService] Skipping auto-refresh due to offline mode - data is ${lastFetch != null ? 'outdated' : 'missing'}'); debugPrint('[SuspectedLocationService] Skipping auto-refresh due to offline mode - data is ${lastFetch != null ? 'outdated' : 'missing'}');
} }
} }
/// Check if background refresh should happen and start it (non-blocking)
Future<void> initBackgroundRefresh({bool offlineMode = false}) async {
// Only auto-fetch if enabled, data is stale or missing, and we are not offline
if (_isEnabled && (await _shouldRefresh()) && !offlineMode) {
debugPrint('[SuspectedLocationService] Starting background auto-refresh of CSV data (older than $_maxAge or missing)');
// Don't await - let it run in background
_fetchData().then((success) {
if (success) {
debugPrint('[SuspectedLocationService] Background auto-refresh completed successfully');
} else {
debugPrint('[SuspectedLocationService] Background auto-refresh failed');
}
}).catchError((error) {
debugPrint('[SuspectedLocationService] Background auto-refresh error: $error');
});
}
}
/// Enable or disable suspected locations /// Enable or disable suspected locations
Future<void> setEnabled(bool enabled) async { Future<void> setEnabled(bool enabled) async {
_isEnabled = enabled; _isEnabled = enabled;
+5
View File
@@ -61,6 +61,11 @@ class SuspectedLocationState extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
/// Start background refresh if needed (non-blocking)
Future<void> initBackgroundRefresh({bool offlineMode = false}) async {
await _service.initBackgroundRefresh(offlineMode: offlineMode);
}
/// Enable or disable suspected locations /// Enable or disable suspected locations
Future<void> setEnabled(bool enabled) async { Future<void> setEnabled(bool enabled) async {
await _service.setEnabled(enabled); await _service.setEnabled(enabled);