offline options globally toggleable

This commit is contained in:
stopflock
2026-07-25 20:40:15 -05:00
parent 6f017fd6c1
commit dfcc64e96e
24 changed files with 489 additions and 92 deletions
+26
View File
@@ -41,11 +41,13 @@ class SettingsState extends ChangeNotifier {
static const String _distanceUnitPrefsKey = 'distance_unit';
static const String _keepScreenAwakePrefsKey = 'keep_screen_awake';
static const String _hideZoomControlsPrefsKey = 'hide_zoom_controls';
static const String _offlineFeaturesEnabledPrefsKey = 'offline_features_enabled';
bool _offlineMode = false;
bool _pauseQueueProcessing = false;
bool _keepScreenAwake = false;
bool _hideZoomControls = false;
bool _offlineFeaturesEnabled = false;
int _maxNodes = kDefaultMaxNodes;
// Default must account for missing secrets (preview builds) even before init() runs
@@ -72,8 +74,10 @@ class SettingsState extends ChangeNotifier {
int get suspectedLocationMinDistance => _suspectedLocationMinDistance;
bool get keepScreenAwake => _keepScreenAwake;
bool get hideZoomControls => _hideZoomControls;
bool get offlineFeaturesEnabled => _offlineFeaturesEnabled;
List<TileProvider> get tileProviders => List.unmodifiable(_tileProviders);
String get selectedTileTypeId => _selectedTileTypeId;
int get navigationAvoidanceDistance => _navigationAvoidanceDistance;
DistanceUnit get distanceUnit => _distanceUnit;
@@ -152,8 +156,14 @@ class SettingsState extends ChangeNotifier {
// Load hide zoom controls setting
_hideZoomControls = prefs.getBool(_hideZoomControlsPrefsKey) ?? false;
// Load offline features enabled setting (defaults to false; migration
// for existing users with pre-existing offline area data lives in
// migrations.dart / migrate_2_10_5)
_offlineFeaturesEnabled = prefs.getBool(_offlineFeaturesEnabledPrefsKey) ?? false;
// Load upload mode (including migration from old test_mode bool)
if (prefs.containsKey(_uploadModePrefsKey)) {
final idx = prefs.getInt(_uploadModePrefsKey) ?? 0;
@@ -432,6 +442,22 @@ class SettingsState extends ChangeNotifier {
}
}
/// Set the master "offline features enabled" toggle. When this is off,
/// offline areas (downloading, browsing, and using cached tiles/nodes) are
/// disabled entirely. Note: any cascading side effects (forcing offline
/// mode off, cancelling active downloads, prompting to delete existing
/// area data) are handled by the caller (see AppState.setOfflineFeaturesEnabled)
/// since those require access to services not owned by SettingsState.
Future<void> setOfflineFeaturesEnabled(bool enabled) async {
if (_offlineFeaturesEnabled != enabled) {
_offlineFeaturesEnabled = enabled;
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_offlineFeaturesEnabledPrefsKey, enabled);
notifyListeners();
}
}
/// Set distance for avoidance of nodes during navigation
Future<void> setNavigationAvoidanceDistance(int distance) async {