Skip to content

Commit

Permalink
feat: Check for airplane mode (closes #129)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Oct 13, 2023
1 parent 39191c5 commit 3d7d161
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/services/manager_service/task.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -78,6 +79,23 @@ Future<void> 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",
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d7d161

Please sign in to comment.