From 7ace123b4bd395720ad292ea871bf68ac0ae9559 Mon Sep 17 00:00:00 2001 From: stopflock Date: Tue, 14 Oct 2025 22:15:52 -0500 Subject: [PATCH] auto-refresh suspected csv, put url in dev_config --- README.md | 2 -- lib/app_state.dart | 2 +- lib/dev_config.dart | 3 +++ lib/services/suspected_location_service.dart | 15 +++++++++------ lib/state/suspected_location_state.dart | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4fac949..c4eaeff 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,6 @@ cp lib/keys.dart.example lib/keys.dart ## Roadmap ### Needed Bugfixes -- Automatically refresh suspected csv on startup if it's enabled, current file is older than a week, and we are not offline -- Suspected locations URL in dev_config - Are offline areas preferred for fast loading even when online? Check working. - Ease up on overpass by pre-caching a larger area. Maybe we could grab the full latest database just like for suspected locations? - Stop failing to fetch tiles; keep retrying after 3. Remove kTileFetchInitialDelayMs, kTileFetchJitter1Ms, etc from dev_config. Fix network indicator - only done when fetch queue is empty! diff --git a/lib/app_state.dart b/lib/app_state.dart index 4bff1ed..3d8cc20 100644 --- a/lib/app_state.dart +++ b/lib/app_state.dart @@ -165,7 +165,7 @@ class AppState extends ChangeNotifier { await _operatorProfileState.init(); await _profileState.init(); - await _suspectedLocationState.init(); + await _suspectedLocationState.init(offlineMode: _settingsState.offlineMode); await _uploadQueueState.init(); await _authState.init(_settingsState.uploadMode); diff --git a/lib/dev_config.dart b/lib/dev_config.dart index e11672e..588ddb2 100644 --- a/lib/dev_config.dart +++ b/lib/dev_config.dart @@ -40,6 +40,9 @@ double bottomPositionFromButtonBar(double spacingAboveButtonBar, double safeArea const String kClientName = 'DeFlock'; // Note: Version is now dynamically retrieved from VersionService +// Suspected locations CSV URL +const String kSuspectedLocationsCsvUrl = 'https://alprwatch.org/pub/flock_utilities_mini_latest.csv'; + // Development/testing features - set to false for production builds const bool kEnableDevelopmentModes = false; // Set to false to hide sandbox/simulate modes and force production mode diff --git a/lib/services/suspected_location_service.dart b/lib/services/suspected_location_service.dart index 4bb5585..b6c6213 100644 --- a/lib/services/suspected_location_service.dart +++ b/lib/services/suspected_location_service.dart @@ -7,6 +7,7 @@ import 'package:latlong2/latlong.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:csv/csv.dart'; +import '../dev_config.dart'; import '../models/suspected_location.dart'; import 'suspected_location_cache.dart'; @@ -15,7 +16,6 @@ class SuspectedLocationService { factory SuspectedLocationService() => _instance; SuspectedLocationService._(); - static const String _csvUrl = 'https://alprwatch.org/pub/flock_utilities_mini_latest.csv'; static const String _prefsKeyEnabled = 'suspected_locations_enabled'; static const Duration _maxAge = Duration(days: 7); static const Duration _timeout = Duration(seconds: 30); @@ -34,15 +34,18 @@ class SuspectedLocationService { bool get isLoading => _isLoading; /// Initialize the service - load from storage and check if refresh needed - Future init() async { + Future init({bool offlineMode = false}) async { await _loadFromStorage(); // Load cache data await _cache.loadFromStorage(); - // Only auto-fetch if enabled and data is stale or missing - if (_isEnabled && _shouldRefresh()) { + // Only auto-fetch if enabled, data is stale or missing, and we are not offline + if (_isEnabled && _shouldRefresh() && !offlineMode) { + debugPrint('[SuspectedLocationService] Auto-refreshing CSV data on startup (older than $_maxAge or missing)'); await _fetchData(); + } else if (_isEnabled && _shouldRefresh() && offlineMode) { + debugPrint('[SuspectedLocationService] Skipping auto-refresh due to offline mode - data is ${_cache.lastFetchTime != null ? 'outdated' : 'missing'}'); } } @@ -100,10 +103,10 @@ class SuspectedLocationService { _isLoading = true; try { onProgress?.call('Downloading CSV data...', null); - debugPrint('[SuspectedLocationService] Fetching CSV data from $_csvUrl'); + debugPrint('[SuspectedLocationService] Fetching CSV data from $kSuspectedLocationsCsvUrl'); final response = await http.get( - Uri.parse(_csvUrl), + Uri.parse(kSuspectedLocationsCsvUrl), headers: { 'User-Agent': 'DeFlock/1.0 (OSM surveillance mapping app)', }, diff --git a/lib/state/suspected_location_state.dart b/lib/state/suspected_location_state.dart index e2e2a73..328706b 100644 --- a/lib/state/suspected_location_state.dart +++ b/lib/state/suspected_location_state.dart @@ -37,8 +37,8 @@ class SuspectedLocationState extends ChangeNotifier { DateTime? get lastFetchTime => _service.lastFetchTime; /// Initialize the state - Future init() async { - await _service.init(); + Future init({bool offlineMode = false}) async { + await _service.init(offlineMode: offlineMode); notifyListeners(); }