From 3d7d16152fd24c1f32b67e6a8d9aaf0bf42ef1c9 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:35:26 +0200 Subject: [PATCH] feat: Check for airplane mode (closes #129) --- lib/services/manager_service/task.dart | 20 +++++++++++++++++++- pubspec.lock | 16 ++++++++++++++++ pubspec.yaml | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/services/manager_service/task.dart b/lib/services/manager_service/task.dart index 0e85adf..eaac08d 100644 --- a/lib/services/manager_service/task.dart +++ b/lib/services/manager_service/task.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:airplane_mode_checker/airplane_mode_checker.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; @@ -30,7 +31,7 @@ void _showPermissionMissingNotification({ AndroidChannelIDs.appIssues.name, l10n.androidNotificationChannel_appIssues_name, channelDescription: - l10n.androidNotificationChannel_appIssues_description, + l10n.androidNotificationChannel_appIssues_description, onlyAlertOnce: true, importance: Importance.max, priority: Priority.max, @@ -78,6 +79,23 @@ Future runBackgroundTask({ final LocationPointService? locationData, final bool force = false, }) async { + FlutterLogs.logInfo( + LOG_TAG, + "Headless Task", + "Checking Airplane mode", + ); + + final status = await AirplaneModeChecker.checkAirplaneMode(); + + if (status == AirplaneModeStatus.on) { + FlutterLogs.logInfo( + LOG_TAG, + "Headless Task", + "----> Airplane mode is on. Skipping headless task.", + ); + return; + } + FlutterLogs.logInfo( LOG_TAG, "Headless Task", diff --git a/pubspec.lock b/pubspec.lock index 6108353..16deb8f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -17,6 +17,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.5.1" + airplane_mode_checker: + dependency: "direct main" + description: + name: airplane_mode_checker + sha256: "16d7de1125056d6f7a9c5c1dc0056afe78c36a9e8fc39768ef9f9c21b07c0d5e" + url: "https://pub.dev" + source: hosted + version: "2.0.0" analyzer: dependency: transitive description: @@ -645,6 +653,14 @@ packages: description: flutter source: sdk version: "0.0.0" + fluttertoast: + dependency: transitive + description: + name: fluttertoast + sha256: "474f7d506230897a3cd28c965ec21c5328ae5605fc9c400cd330e9e9d6ac175c" + url: "https://pub.dev" + source: hosted + version: "8.2.2" frontend_server_client: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index af7f3a3..7bff767 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -102,6 +102,7 @@ dependencies: collection: ^1.17.1 background_locator_2: ^2.0.6 queue: ^3.1.0+2 + airplane_mode_checker: ^2.0.0 # Uncomment this for publishing FLOSS variant # Taken from https://github.com/Zverik/every_door/blob/aaf8d2fdeac483041bcac2c7c79ef760b99dff2b/pubspec.yaml#L55