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

Commit

Permalink
Merge pull request #123 from Myzel394/fix-live-location
Browse files Browse the repository at this point in the history
fix: Do not skip location update when `useRealtimeUpdates` is enabled
  • Loading branch information
Myzel394 authored Oct 1, 2023
2 parents 65d0a0b + 850cef4 commit 852f809
Showing 1 changed file with 8 additions and 5 deletions.
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

0 comments on commit 852f809

Please sign in to comment.