Skip to content

Commit

Permalink
Remove legacy connected gear checl
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 18, 2024
1 parent 072978c commit b8bbde8
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 34 deletions.
4 changes: 0 additions & 4 deletions lib/Backend/Bluetooth/bluetooth_manager_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ StreamSubscription<void>? _keepAliveStreamSubscription;

final _bluetoothPlusLogger = log.Logger('BluetoothPlus');

ValueNotifier<bool> isAnyGearConnected = ValueNotifier(false);
ValueNotifier<bool> isBluetoothEnabled = ValueNotifier(false);

bool _didInitFlutterBluePlus = false;
Expand Down Expand Up @@ -101,7 +100,6 @@ Future<void> initFlutterBluePlus(InitFlutterBluePlusRef ref) async {
}
// The timer used for the time value on the battery level graph
statefulDevice.stopWatch.start();
isAnyGearConnected.value = true;
if (HiveProxy.getOrDefault(settings, keepAwake, defaultValue: keepAwakeDefault)) {
_bluetoothPlusLogger.fine('Enabling wakelock');
WakelockPlus.enable();
Expand Down Expand Up @@ -156,7 +154,6 @@ Future<void> initFlutterBluePlus(InitFlutterBluePlusRef ref) async {
element.enabled = false;
},
);
isAnyGearConnected.value = false;
_bluetoothPlusLogger.finer('Disabling wakelock');
// stop wakelock if its started
WakelockPlus.disable();
Expand Down Expand Up @@ -326,7 +323,6 @@ Future<void> initFlutterBluePlus(InitFlutterBluePlusRef ref) async {
ref.read(knownDevicesProvider).forEach(
(key, value) => value.deviceConnectionState.value = ConnectivityState.disconnected,
);
isAnyGearConnected.value = false;
isBluetoothEnabled.value = false;
_didInitFlutterBluePlus = false; // Allow restarting ble stack
});
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/sensors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
TriggerDefinition(this.ref);

Future<void> sendCommands(String name, Ref ref) async {
if (!isAnyGearConnected.value) {
if (ref.read(getAvailableGearProvider).isEmpty) {
return;
}
actions.values.flattened.where((e) => actionTypes.firstWhere((element) => element.name == name).uuid == e.uuid).forEach(
Expand Down
4 changes: 2 additions & 2 deletions lib/Frontend/Widgets/back_button_to_close.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../Backend/Bluetooth/bluetooth_manager_plus.dart';
import '../../Backend/device_registry.dart';
import '../translation_string_definitions.dart';

class BackButtonToClose extends ConsumerStatefulWidget {
Expand Down Expand Up @@ -35,7 +35,7 @@ class _BackButtonToCloseState extends ConsumerState<BackButtonToClose> {
// ignore: avoid_positional_boolean_parameters
bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) {
if (info.currentRoute(context)!.isFirst && info.currentRoute(context)!.isCurrent) {
if (isAnyGearConnected.value) {
if (ref.read(getAvailableGearProvider).isNotEmpty) {
return true;
}
if (timer.isActive) {
Expand Down
5 changes: 3 additions & 2 deletions lib/Frontend/Widgets/bt_app_state_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../Backend/Bluetooth/bluetooth_manager_plus.dart';
import '../../Backend/device_registry.dart';
import '../../Backend/logging_wrappers.dart';
import '../../constants.dart';

Expand All @@ -28,7 +29,7 @@ class _BtAppStateControllerState extends ConsumerState<BtAppStateController> {
}
},
onPause: () {
if (!isAnyGearConnected.value && ref.exists(initFlutterBluePlusProvider)) {
if (ref.read(getAvailableGearProvider).isEmpty && ref.exists(initFlutterBluePlusProvider)) {
ref.invalidate(initFlutterBluePlusProvider);
}
},
Expand All @@ -48,7 +49,7 @@ class _BtAppStateControllerState extends ConsumerState<BtAppStateController> {
void dispose() {
super.dispose();
_listener.dispose();
if (!isAnyGearConnected.value && ref.exists(initFlutterBluePlusProvider)) {
if (ref.read(getAvailableGearProvider).isEmpty && ref.exists(initFlutterBluePlusProvider)) {
ref.invalidate(initFlutterBluePlusProvider);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Frontend/Widgets/known_gear_scan_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:sentry_hive/sentry_hive.dart';
import '../../Backend/Bluetooth/bluetooth_manager.dart';
import '../../Backend/Bluetooth/bluetooth_manager_plus.dart';
import '../../Backend/Definitions/Device/device_definition.dart';
import '../../Backend/device_registry.dart';
import '../../constants.dart';

final knownGearScanControllerLogger = log.Logger('KnownGearScanController');
Expand Down Expand Up @@ -39,7 +40,7 @@ class _KnownGearScanControllerState extends ConsumerState<KnownGearScanControlle
},
//onResume: () => _handleTransition('resume'),
onHide: () async {
if (!isAnyGearConnected.value) {
if (ref.read(getAvailableGearProvider).isEmpty) {
await stopScan();
}
},
Expand Down
5 changes: 1 addition & 4 deletions lib/Frontend/Widgets/scan_for_new_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class _ScanForNewDevice extends ConsumerState<ScanForNewDevice> {
baseStoredDevice = BaseStoredDevice(value.uuid, "DEV${value.deviceType.name}", value.deviceType.color(ref: ref).value)..name = getNameFromBTName(value.btName);
statefulDevice = BaseStatefulDevice(value, baseStoredDevice);
statefulDevice.deviceConnectionState.value = ConnectivityState.connected;
isAnyGearConnected.value = true;
if (!ref.read(knownDevicesProvider).containsKey(baseStoredDevice.btMACAddress)) {
ref.read(knownDevicesProvider.notifier).add(statefulDevice);
}
Expand All @@ -216,9 +215,7 @@ class _ScanForNewDevice extends ConsumerState<ScanForNewDevice> {
.where(
(element) => element.deviceConnectionState.value == ConnectivityState.connected,
)
.isEmpty) {
isAnyGearConnected.value = false;
}
.isEmpty) {}
context.pop();
},
),
Expand Down
14 changes: 0 additions & 14 deletions lib/Frontend/pages/developer/developer_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

import '../../../Backend/Bluetooth/bluetooth_manager_plus.dart';
import '../../../Backend/logging_wrappers.dart';
import '../../../constants.dart';
import '../../../main.dart';
Expand Down Expand Up @@ -108,19 +107,6 @@ class _DeveloperMenuState extends ConsumerState<DeveloperMenu> {
},
),
),
ListTile(
title: const Text("isAnyGearConnected"),
trailing: Switch(
value: isAnyGearConnected.value,
onChanged: (bool value) {
setState(
() {
isAnyGearConnected.value = value;
},
);
},
),
),
ListTile(
title: const Text("SentryEnvironment"),
subtitle: FutureBuilder(
Expand Down
2 changes: 0 additions & 2 deletions test/Backend/action_registry_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart' as flTest;
import 'package:flutter_test/flutter_test.dart';
import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart';
import 'package:tail_app/Backend/Bluetooth/bluetooth_manager_plus.dart';
import 'package:tail_app/Backend/Definitions/Action/base_action.dart';
import 'package:tail_app/Backend/Definitions/Device/device_definition.dart';
import 'package:tail_app/Backend/action_registry.dart';
Expand All @@ -18,7 +17,6 @@ void main() {
});
tearDown(() async {
await deleteHive();
isAnyGearConnected.value = false;
});
test('All actions count', () {
expect(ActionRegistry.allCommands.length, 26);
Expand Down
2 changes: 0 additions & 2 deletions test/Backend/device_definition_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart' as flTest;
import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart';
import 'package:tail_app/Backend/Bluetooth/bluetooth_manager_plus.dart';
import 'package:tail_app/Backend/Definitions/Device/device_definition.dart';
import 'package:test/test.dart';

Expand All @@ -16,7 +15,6 @@ void main() {
});
tearDown(() async {
await deleteHive();
isAnyGearConnected.value = false;
});
group('Stateful Device event listeners', () {
test('Battery Levels', () async {
Expand Down
2 changes: 0 additions & 2 deletions test/testing_utils/gear_utils.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart';
import 'package:tail_app/Backend/Bluetooth/bluetooth_manager_plus.dart';
import 'package:tail_app/Backend/Definitions/Device/device_definition.dart';
import 'package:tail_app/Backend/device_registry.dart';
import 'package:tail_app/Backend/logging_wrappers.dart';
Expand All @@ -14,7 +13,6 @@ Future<BaseStatefulDevice> createAndStoreGear(String gearBtName, ProviderContain
baseStoredDevice = BaseStoredDevice(baseDeviceDefinition.uuid, "$gearMacPrefix${baseDeviceDefinition.deviceType.name}", baseDeviceDefinition.deviceType.color(ref: ref).value)..name = getNameFromBTName(baseDeviceDefinition.btName);
statefulDevice = BaseStatefulDevice(baseDeviceDefinition, baseStoredDevice);
statefulDevice.deviceConnectionState.value = ConnectivityState.connected;
isAnyGearConnected.value = true;
if (!ref.read(knownDevicesProvider).containsKey(baseStoredDevice.btMACAddress)) {
await ref.read(knownDevicesProvider.notifier).add(statefulDevice);
}
Expand Down

0 comments on commit b8bbde8

Please sign in to comment.