Merge pull request #163 from reb1995/keep-screen-awake-while-using-app

Keep screen awake while using app. Update translations for new settings.
This commit is contained in:
stopflock
2026-05-12 15:18:32 -05:00
committed by GitHub
17 changed files with 146 additions and 3 deletions
+5 -1
View File
@@ -156,6 +156,7 @@ class AppState extends ChangeNotifier {
int get maxNodes => _settingsState.maxNodes;
UploadMode get uploadMode => _settingsState.uploadMode;
FollowMeMode get followMeMode => _settingsState.followMeMode;
bool get keepScreenAwake => _settingsState.keepScreenAwake;
bool get proximityAlertsEnabled => _settingsState.proximityAlertsEnabled;
int get proximityAlertDistance => _settingsState.proximityAlertDistance;
@@ -172,7 +173,6 @@ class AppState extends ChangeNotifier {
TileType? get selectedTileType => _settingsState.selectedTileType;
TileProvider? get selectedTileProvider => _settingsState.selectedTileProvider;
// Upload queue state
int get pendingCount => _uploadQueueState.pendingCount;
@@ -678,6 +678,10 @@ class AppState extends ChangeNotifier {
}
}
Future<void> setKeepScreenAwake(bool enabled) async {
await _settingsState.setKeepScreenAwake(enabled);
}
Future<void> setPauseQueueProcessing(bool enabled) async {
await _settingsState.setPauseQueueProcessing(enabled);
if (!enabled) {
+5
View File
@@ -74,8 +74,13 @@
"advancedSettings": "Erweiterte Einstellungen",
"advancedSettingsSubtitle": "Leistungs-, Warnungs- und Kachelanbieter-Einstellungen",
"proximityAlerts": "Näherungswarnungen",
"keepScreenAwake": "Bildschirm Aktiv Lassen",
"networkStatusIndicator": "Netzwerkstatus-Anzeige"
},
"keepScreenAwake": {
"title": "Bildschirm während der App-Nutzung aktiv lassen",
"subtitle": "Verhindert, dass sich der Bildschirm während der Nutzung der App automatisch ausschaltet"
},
"proximityAlerts": {
"getNotified": "Benachrichtigung erhalten beim Annähern an Überwachungsgeräte",
"batteryUsage": "Verbraucht zusätzlich Batterie für kontinuierliche Standortüberwachung",
+6 -1
View File
@@ -111,7 +111,12 @@
"advancedSettings": "Advanced Settings",
"advancedSettingsSubtitle": "Performance, alerts, and tile provider settings",
"proximityAlerts": "Proximity Alerts",
"networkStatusIndicator": "Network Status Indicator"
"networkStatusIndicator": "Network Status Indicator",
"keepScreenAwake": "Keep Screen Awake"
},
"keepScreenAwake": {
"title": "Keep screen awake while using app",
"subtitle": "Prevents the screen from turning off automatically while using the app"
},
"proximityAlerts": {
"getNotified": "Get notified when approaching surveillance devices",
+5
View File
@@ -111,8 +111,13 @@
"advancedSettings": "Configuración Avanzada",
"advancedSettingsSubtitle": "Configuración de rendimiento, alertas y proveedores de teselas",
"proximityAlerts": "Alertas de Proximidad",
"keepScreenAwake": "Mantener la Pantalla Encendida",
"networkStatusIndicator": "Indicador de Estado de Red"
},
"keepScreenAwake": {
"title": "Mantener la pantalla encendida mientras se usa la app",
"subtitle": "Evita que la pantalla se apague automáticamente mientras se usa la app"
},
"proximityAlerts": {
"getNotified": "Recibe notificaciones al acercarte a dispositivos de vigilancia",
"batteryUsage": "Usa batería extra para monitoreo continuo de ubicación",
+5
View File
@@ -111,8 +111,13 @@
"advancedSettings": "Paramètres Avancés",
"advancedSettingsSubtitle": "Paramètres de performance, alertes et fournisseurs de tuiles",
"proximityAlerts": "Alertes de Proximité",
"keepScreenAwake": "Maintenir l'écran Allumé",
"networkStatusIndicator": "Indicateur de Statut Réseau"
},
"keepScreenAwake": {
"title": "Maintenir l'écran allumé lors de l'utilisation de l'application",
"subtitle": "Empêche l'écran de s'éteindre automatiquement pendant l'utilisation de l'application"
},
"proximityAlerts": {
"getNotified": "Recevoir des notifications en s'approchant de dispositifs de surveillance",
"batteryUsage": "Utilise de la batterie supplémentaire pour la surveillance continue de la localisation",
+5
View File
@@ -111,8 +111,13 @@
"advancedSettings": "Impostazioni Avanzate",
"advancedSettingsSubtitle": "Impostazioni di prestazioni, avvisi e fornitori di tessere",
"proximityAlerts": "Avvisi di Prossimità",
"keepScreenAwake": "Mantieni lo Schermo Attivo",
"networkStatusIndicator": "Indicatore di Stato di Rete"
},
"keepScreenAwake": {
"title": "Mantieni lo schermo attivo durante l'utilizzo dell'app",
"subtitle": "Impedisce allo schermo di spegnersi automaticamente durante l'utilizzo dell'app"
},
"proximityAlerts": {
"getNotified": "Ricevi notifiche quando ti avvicini a dispositivi di sorveglianza",
"batteryUsage": "Utilizza batteria extra per il monitoraggio continuo della posizione",
+5
View File
@@ -111,8 +111,13 @@
"advancedSettings": "Geavanceerde Instellingen",
"advancedSettingsSubtitle": "Prestaties, waarschuwingen en tile provider instellingen",
"proximityAlerts": "Nabijheids Waarschuwingen",
"keepScreenAwake": "Scherm Actief Houden",
"networkStatusIndicator": "Netwerk Status Indicator"
},
"keepScreenAwake": {
"title": "Houd het scherm actief tijdens het gebruik van de app",
"subtitle": "Voorkomt dat het scherm automatisch uitschakelt tijdens het gebruik van de app"
},
"proximityAlerts": {
"getNotified": "Krijg meldingen wanneer u surveillance apparaten nadert",
"batteryUsage": "Gebruikt extra batterij voor continue locatie monitoring",
+5
View File
@@ -111,8 +111,13 @@
"advancedSettings": "Ustawienia Zaawansowane",
"advancedSettingsSubtitle": "Wydajność, alerty i ustawienia dostawców kafelków",
"proximityAlerts": "Alerty Bliskości",
"keepScreenAwake": "Nie Wygaszaj Ekranu",
"networkStatusIndicator": "Wskaźnik Stanu Sieci"
},
"keepScreenAwake": {
"title": "Nie wygaszaj ekranu podczas korzystania z aplikacji",
"subtitle": "Zapobiega automatycznemu wygaszaniu ekranu podczas korzystania z aplikacji"
},
"proximityAlerts": {
"getNotified": "Otrzymuj powiadomienia przy zbliżaniu się do urządzeń nadzoru",
"batteryUsage": "Używa dodatkowej baterii do ciągłego monitorowania lokalizacji",
+5
View File
@@ -111,8 +111,13 @@
"advancedSettings": "Configurações Avançadas",
"advancedSettingsSubtitle": "Configurações de desempenho, alertas e provedores de mapas",
"proximityAlerts": "Alertas de Proximidade",
"keepScreenAwake": "Manter Ecrã Ativa",
"networkStatusIndicator": "Indicador de Status de Rede"
},
"keepScreenAwake": {
"title": "Manter o ecrã ativo durante o uso do app",
"subtitle": "Impede que o ecrã se desligue automaticamente enquanto a app estiver em uso"
},
"proximityAlerts": {
"getNotified": "Receba notificações ao se aproximar de dispositivos de vigilância",
"batteryUsage": "Usa bateria extra para monitoramento contínuo de localização",
+5
View File
@@ -111,8 +111,13 @@
"advancedSettings": "Gelişmiş Ayarlar",
"advancedSettingsSubtitle": "Performans, uyarılar ve döşeme sağlayıcı ayarları",
"proximityAlerts": "Yakınlık Uyarıları",
"keepScreenAwake": "Ekranı Açık Tut",
"networkStatusIndicator": "Ağ Durumu Göstergesi"
},
"keepScreenAwake": {
"title": "Uygulamayı kullanırken ekranı açık tut",
"subtitle": "Uygulamayı kullanırken ekranın otomatik olarak kapanmasını engeller"
},
"proximityAlerts": {
"getNotified": "Gözetleme cihazlarına yaklaşırken bildirim al",
"batteryUsage": "Sürekli konum izleme için ekstra batarya kullanır",
+5
View File
@@ -111,8 +111,13 @@
"advancedSettings": "Розширені Налаштування",
"advancedSettingsSubtitle": "Продуктивність, сповіщення та налаштування постачальників плиток",
"proximityAlerts": "Сповіщення Про Близькість",
"keepScreenAwake": "Тримати екран активним",
"networkStatusIndicator": "Індикатор Стану Мережі"
},
"keepScreenAwake": {
"title": "Тримати екран активним під час використання програми",
"subtitle": "Запобігає автоматичному вимкненню екрана під час використання програми"
},
"proximityAlerts": {
"getNotified": "Отримувати сповіщення при наближенні до пристроїв спостереження",
"batteryUsage": "Використовує додаткову батарею для безперервного моніторингу місцезнаходження",
+5
View File
@@ -111,8 +111,13 @@
"advancedSettings": "高级设置",
"advancedSettingsSubtitle": "性能、警报和地图提供商设置",
"proximityAlerts": "邻近警报",
"keepScreenAwake": "保持屏幕常亮",
"networkStatusIndicator": "网络状态指示器"
},
"keepScreenAwake": {
"title": "使用应用时保持屏幕常亮",
"subtitle": "防止在使用应用期间屏幕自动熄灭"
},
"proximityAlerts": {
"getNotified": "接近监控设备时接收通知",
"batteryUsage": "使用额外电量进行连续位置监控",
@@ -3,6 +3,7 @@ import 'settings/sections/max_nodes_section.dart';
import 'settings/sections/proximity_alerts_section.dart';
import 'settings/sections/suspected_locations_section.dart';
import 'settings/sections/tile_provider_section.dart';
import 'settings/sections/keep_screen_awake_section.dart';
import '../services/localization_service.dart';
class AdvancedSettingsScreen extends StatelessWidget {
@@ -32,6 +33,8 @@ class AdvancedSettingsScreen extends StatelessWidget {
Divider(),
SuspectedLocationsSection(),
Divider(),
KeepScreenAwakeSection(),
Divider(),
// NetworkStatusSection(), // Commented out - network status indicator now defaults to enabled
// Divider(),
TileProviderSection(),
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../../app_state.dart';
import '../../../services/localization_service.dart';
class KeepScreenAwakeSection extends StatelessWidget {
const KeepScreenAwakeSection({super.key});
@override
Widget build(BuildContext context) {
// Standard Pattern: Use AnimatedBuilder to respond to language/localization changes
return AnimatedBuilder(
animation: LocalizationService.instance,
builder: (context, child) {
final locService = LocalizationService.instance;
final appState = context.watch<AppState>();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Bold Section Header (matches Max Nodes, Proximity, etc.)
Text(
locService.t('settings.keepScreenAwake'),
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
// The Functional Toggle
SwitchListTile(
contentPadding: EdgeInsets.zero, // Aligns switch text with the bold header
title: Text(locService.t('keepScreenAwake.title')),
subtitle: Text(
locService.t('keepScreenAwake.subtitle'),
style: const TextStyle(fontSize: 12),
),
value: appState.keepScreenAwake,
onChanged: (bool value) {
appState.setKeepScreenAwake(value);
},
),
],
);
},
);
}
}
+17 -1
View File
@@ -39,9 +39,11 @@ class SettingsState extends ChangeNotifier {
static const String _pauseQueueProcessingPrefsKey = 'pause_queue_processing';
static const String _navigationAvoidanceDistancePrefsKey = 'navigation_avoidance_distance';
static const String _distanceUnitPrefsKey = 'distance_unit';
static const String _keepScreenAwakePrefsKey = 'keep_screen_awake';
bool _offlineMode = false;
bool _pauseQueueProcessing = false;
bool _keepScreenAwake = false;
int _maxNodes = kDefaultMaxNodes;
// Default must account for missing secrets (preview builds) even before init() runs
UploadMode _uploadMode = (kEnableDevelopmentModes || !kHasOsmSecrets) ? UploadMode.simulate : UploadMode.production;
@@ -65,6 +67,7 @@ class SettingsState extends ChangeNotifier {
int get proximityAlertDistance => _proximityAlertDistance;
bool get networkStatusIndicatorEnabled => _networkStatusIndicatorEnabled;
int get suspectedLocationMinDistance => _suspectedLocationMinDistance;
bool get keepScreenAwake => _keepScreenAwake;
List<TileProvider> get tileProviders => List.unmodifiable(_tileProviders);
String get selectedTileTypeId => _selectedTileTypeId;
int get navigationAvoidanceDistance => _navigationAvoidanceDistance;
@@ -138,6 +141,9 @@ class SettingsState extends ChangeNotifier {
// Load suspected location minimum distance
_suspectedLocationMinDistance = prefs.getInt(_suspectedLocationMinDistancePrefsKey) ?? 100;
// Load keep screen awake setting
_keepScreenAwake = prefs.getBool(_keepScreenAwakePrefsKey) ?? false;
// Load upload mode (including migration from old test_mode bool)
if (prefs.containsKey(_uploadModePrefsKey)) {
@@ -397,7 +403,17 @@ class SettingsState extends ChangeNotifier {
}
}
// Set distance for avoidance of nodes during navigation
/// Set keep screen awake enabled/disabled
Future<void> setKeepScreenAwake(bool enabled) async {
if (_keepScreenAwake != enabled) {
_keepScreenAwake = enabled;
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keepScreenAwakePrefsKey, enabled);
notifyListeners();
}
}
/// Set distance for avoidance of nodes during navigation
Future<void> setNavigationAvoidanceDistance(int distance) async {
if (_navigationAvoidanceDistance != distance) {
_navigationAvoidanceDistance = distance;
+18
View File
@@ -3,6 +3,7 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_animations/flutter_map_animations.dart';
import 'package:latlong2/latlong.dart';
import 'package:provider/provider.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import '../app_state.dart' show AppState, FollowMeMode;
import '../services/offline_area_service.dart';
@@ -84,7 +85,20 @@ class MapViewState extends State<MapView> {
// Track active pointers to suppress follow-me animations during touch
int _activePointers = 0;
bool _isWakelockEnabled = false;
void _updateWakelock(bool shouldBeAwake) {
if (_isWakelockEnabled != shouldBeAwake) {
_isWakelockEnabled = shouldBeAwake;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (shouldBeAwake) {
WakelockPlus.enable();
} else {
WakelockPlus.disable();
}
});
}
}
@override
void initState() {
@@ -213,6 +227,7 @@ class MapViewState extends State<MapView> {
_nodeController.dispose();
_tileManager.dispose();
_gpsController.dispose();
WakelockPlus.disable();
// PrefetchAreaService no longer used - replaced with NodeDataManager
super.dispose();
}
@@ -278,6 +293,9 @@ class MapViewState extends State<MapView> {
final session = appState.session;
final editSession = appState.editSession;
// Keep screen awake based on user setting
_updateWakelock(appState.keepScreenAwake);
// Check if enabled profiles changed and refresh nodes if needed
_nodeController.checkAndHandleProfileChanges(
currentEnabledProfiles: appState.enabledProfiles,
+1
View File
@@ -38,6 +38,7 @@ dependencies:
package_info_plus: ^9.0.0
csv: ^6.0.0
collection: ^1.18.0
wakelock_plus: ^1.5.2
dev_dependencies:
flutter_test: