Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

fix: Do not skip location update when useRealtimeUpdates is enabled #123

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/services/manager_service/task.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;

Expand Down Expand Up @@ -83,10 +83,13 @@ Future<void> 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,
Expand Down