Automatic prevent suspend

This commit is contained in:
Anton Tananaev 2025-06-13 15:11:58 -07:00
parent d669d9eef8
commit d6fdbc0652
3 changed files with 2 additions and 16 deletions

View file

@ -18,7 +18,6 @@
"distanceLabel": "Distance (meters)",
"heartbeatLabel": "Heartbeat (seconds)",
"bufferLabel": "Offline buffering",
"preventSuspendLabel": "Prevent suspend",
"disableElasticityLabel": "Disable elasticity",
"stopDetectionLabel": "Stop detection",
"trackingLabel": "Continuous tracking",

View file

@ -15,7 +15,6 @@ class Preferences {
static const String distance = 'distance';
static const String heartbeat = 'heartbeat';
static const String buffer = 'buffer';
static const String preventSuspend = 'prevent_suspend';
static const String stopDetection = 'stop_detection';
static Future<void> init() async {
@ -25,7 +24,7 @@ class Preferences {
: SharedPreferencesOptions(),
cacheOptions: SharedPreferencesWithCacheOptions(
allowList: {
id, url, accuracy, interval, distance, buffer, heartbeat, preventSuspend, stopDetection,
id, url, accuracy, interval, distance, buffer, heartbeat, stopDetection,
'device_id_preference', 'server_url_preference', 'accuracy_preference',
'frequency_preference', 'distance_preference', 'buffer_preference',
},
@ -75,7 +74,7 @@ class Preferences {
logMaxDays: 1,
locationTemplate: _locationTemplate(),
showsBackgroundLocationIndicator: false,
preventSuspend: instance.getBool(preventSuspend),
preventSuspend: heartbeatInterval > 0,
disableElasticity: true,
disableStopDetection: instance.getBool(stopDetection) == false,
pausesLocationUpdatesAutomatically: instance.getBool(stopDetection) == false,

View file

@ -16,7 +16,6 @@ class SettingsScreen extends StatefulWidget {
class _SettingsScreenState extends State<SettingsScreen> {
bool buffering = true;
bool preventSuspend = false;
bool stopDetection = false;
bool advanced = false;
@ -29,7 +28,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
void _initState() async {
setState(() {
buffering = Preferences.instance.getBool(Preferences.buffer) ?? true;
preventSuspend = Preferences.instance.getBool(Preferences.preventSuspend) ?? false;
stopDetection = Preferences.instance.getBool(Preferences.stopDetection) ?? true;
});
}
@ -171,16 +169,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
setState(() => stopDetection = value);
},
),
if (advanced && Platform.isIOS)
SwitchListTile(
title: Text(AppLocalizations.of(context)!.preventSuspendLabel),
value: preventSuspend,
onChanged: (value) async {
await Preferences.instance.setBool(Preferences.preventSuspend, value);
await bg.BackgroundGeolocation.setConfig(Preferences.geolocationConfig());
setState(() => preventSuspend = value);
},
),
],
),
);