Skip to content

Commit

Permalink
Add wakelock support
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Feb 28, 2024
1 parent 69d9a47 commit d09c036
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/Backend/Bluetooth/BluetoothManager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Backend/Sensors.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

import '../AutoMove.dart';
import '../Definitions/Device/BaseDeviceDefinition.dart';
Expand Down Expand Up @@ -199,6 +200,11 @@ StreamSubscription<ConnectionStateUpdate> btConnectStateHandler(BtConnectStateHa
ForegroundServiceHandler.notification.setTitle("Gear Connected");
ForegroundService().start();
}
if (event.connectionState == DeviceConnectionState.connected) {
if (SentryHive.box('settings').get('keepAwake', defaultValue: false)) {
WakelockPlus.enable();
}
}
if (knownDevices.containsKey(event.deviceId)) {
knownDevices[event.deviceId]?.deviceConnectionState.value = event.connectionState;
if (event.connectionState == DeviceConnectionState.disconnected) {
Expand Down Expand Up @@ -232,6 +238,7 @@ StreamSubscription<ConnectionStateUpdate> btConnectStateHandler(BtConnectStateHa
ref.read(triggerListProvider).where((element) => element.enabled).forEach((element) {
element.enabled = false;
});
WakelockPlus.disable();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/pages/Shell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class _NavigationDrawerExampleState extends ConsumerState<NavigationDrawerExampl
builder: (BuildContext context) {
return DraggableScrollableSheet(
expand: false,
initialChildSize: 1,
initialChildSize: 0.9,
builder: (BuildContext context, ScrollController scrollController) {
return ManageGear(
ref: ref,
Expand Down
24 changes: 24 additions & 0 deletions lib/Frontend/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import 'package:feedback_sentry/feedback_sentry.dart';
import 'package:flex_color_picker/flex_color_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Backend/Bluetooth/BluetoothManager.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

import '../../main.dart';
import '../intnDefs.dart';
Expand Down Expand Up @@ -53,6 +56,27 @@ class _SettingsState extends ConsumerState<Settings> {
},
),
),
ListTile(
//This is handled separately as I was storing settings in a provider, which is unavailable during sentry init
title: Text("Keep screen on"),
leading: const Icon(Icons.phone_android),
subtitle: Text("Keep the screen on when gear is connected"),
trailing: Switch(
value: SentryHive.box('settings').get('keepAwake', defaultValue: false),
onChanged: (bool value) {
setState(() {
SentryHive.box('settings').put('keepAwake', value);
if (ref.read(knownDevicesProvider).values.where((element) => element.deviceConnectionState == DeviceConnectionState.connected).isNotEmpty) {
if (value) {
WakelockPlus.enable();
} else {
WakelockPlus.disable();
}
}
});
},
),
),
ListTile(
title: Text(
settingsAppColor(),
Expand Down
5 changes: 3 additions & 2 deletions lib/Frontend/pages/triggers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ class _TriggersState extends ConsumerState<Triggers> {
);
},
),
)
]..addAll(getTriggerOptions(triggersList[index])),
),
...getTriggerOptions(triggersList[index])
],
);
});
},
Expand Down
26 changes: 25 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.2"
dbus:
dependency: transitive
description:
name: dbus
sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac"
url: "https://pub.dev"
source: hosted
version: "0.7.10"
device_info_plus:
dependency: transitive
description:
Expand Down Expand Up @@ -678,7 +686,7 @@ packages:
source: hosted
version: "0.6.7"
json_annotation:
dependency: transitive
dependency: "direct dev"
description:
name: json_annotation
sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467
Expand Down Expand Up @@ -1506,6 +1514,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "13.0.0"
wakelock_plus:
dependency: "direct main"
description:
name: wakelock_plus
sha256: f268ca2116db22e57577fb99d52515a24bdc1d570f12ac18bb762361d43b043d
url: "https://pub.dev"
source: hosted
version: "1.1.4"
wakelock_plus_platform_interface:
dependency: transitive
description:
name: wakelock_plus_platform_interface
sha256: "40fabed5da06caff0796dc638e1f07ee395fb18801fbff3255a2372db2d80385"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
watcher:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies:
google_fonts: ^6.1.0
fl_chart: ^0.66.2
file_picker: ^6.1.1
wakelock_plus:
dev_dependencies:
build_runner:
flutter_test:
Expand All @@ -67,6 +68,7 @@ dev_dependencies:
sentry_dart_plugin: ^1.7.1
intl_translation:
hive_generator: ^2.0.1
json_annotation: ^4.8.1
flutter:
uses-material-design: true
generate: true
Expand Down

0 comments on commit d09c036

Please sign in to comment.