From 850cef4fb0f93018d73bbd93b0e49659286b938e Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 1 Oct 2023 09:18:21 +0200 Subject: [PATCH] fix: Do not skip location update when `useRealtimeUpdates` is enabled --- lib/services/manager_service/task.dart | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/services/manager_service/task.dart b/lib/services/manager_service/task.dart index 3f393b5..aa5445b 100644 --- a/lib/services/manager_service/task.dart +++ b/lib/services/manager_service/task.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_logs/flutter_logs.dart'; import 'package:locus/constants/notifications.dart'; @@ -10,7 +11,6 @@ import 'package:locus/services/manager_service/helpers.dart'; import 'package:locus/services/settings_service/index.dart'; import 'package:locus/utils/device/index.dart'; import 'package:locus/utils/permissions/has-granted.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; const PERMISSION_MISSING_NOTIFICATION_ID = 394001; @@ -83,10 +83,13 @@ Future runBackgroundTask({ ); final isDeviceBatterySaverEnabled = await isBatterySaveModeEnabled(); - if ((isDeviceBatterySaverEnabled || settings.alwaysUseBatterySaveMode) && - settings.lastHeadlessRun != null && - DateTime.now().difference(settings.lastHeadlessRun!).abs() <= - BATTERY_SAVER_ENABLED_MINIMUM_TIME_BETWEEN_HEADLESS_RUNS) { + final shouldRunBasedOnBatterySaver = + settings.useRealtimeUpdates || !isDeviceBatterySaverEnabled; + final shouldRunBasedOnLastRun = settings.lastHeadlessRun == null || + DateTime.now().difference(settings.lastHeadlessRun!).abs() > + BATTERY_SAVER_ENABLED_MINIMUM_TIME_BETWEEN_HEADLESS_RUNS; + + if (shouldRunBasedOnBatterySaver && shouldRunBasedOnLastRun) { // We don't want to run the headless task too often when the battery saver is enabled. FlutterLogs.logInfo( LOG_TAG,