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)", "distanceLabel": "Distance (meters)",
"heartbeatLabel": "Heartbeat (seconds)", "heartbeatLabel": "Heartbeat (seconds)",
"bufferLabel": "Offline buffering", "bufferLabel": "Offline buffering",
"preventSuspendLabel": "Prevent suspend",
"disableElasticityLabel": "Disable elasticity", "disableElasticityLabel": "Disable elasticity",
"stopDetectionLabel": "Stop detection", "stopDetectionLabel": "Stop detection",
"trackingLabel": "Continuous tracking", "trackingLabel": "Continuous tracking",

View file

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

View file

@ -16,7 +16,6 @@ class SettingsScreen extends StatefulWidget {
class _SettingsScreenState extends State<SettingsScreen> { class _SettingsScreenState extends State<SettingsScreen> {
bool buffering = true; bool buffering = true;
bool preventSuspend = false;
bool stopDetection = false; bool stopDetection = false;
bool advanced = false; bool advanced = false;
@ -29,7 +28,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
void _initState() async { void _initState() async {
setState(() { setState(() {
buffering = Preferences.instance.getBool(Preferences.buffer) ?? true; buffering = Preferences.instance.getBool(Preferences.buffer) ?? true;
preventSuspend = Preferences.instance.getBool(Preferences.preventSuspend) ?? false;
stopDetection = Preferences.instance.getBool(Preferences.stopDetection) ?? true; stopDetection = Preferences.instance.getBool(Preferences.stopDetection) ?? true;
}); });
} }
@ -171,16 +169,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
setState(() => stopDetection = value); 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);
},
),
], ],
), ),
); );