Skip to content

Commit

Permalink
Move gear debug page to scan sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed May 24, 2024
1 parent d87d558 commit d1cfd47
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 58 deletions.
48 changes: 48 additions & 0 deletions lib/Frontend/Widgets/scan_for_new_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import 'package:animate_do/animate_do.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:sentry_hive/sentry_hive.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 '../../Backend/device_registry.dart';
import '../../constants.dart';
import '../../gen/assets.gen.dart';
import '../../main.dart';
Expand Down Expand Up @@ -129,6 +131,52 @@ class _ScanForNewDevice extends ConsumerState<ScanForNewDevice> {
);
},
),
if (SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault)) ...[
ListTile(
title: const Text("Add demo gear"),
leading: const Icon(Icons.add),
trailing: DropdownMenu<BaseDeviceDefinition>(
initialSelection: null,
onSelected: (value) {
if (value != null) {
setState(
() {
BaseStoredDevice baseStoredDevice;
BaseStatefulDevice statefulDevice;
baseStoredDevice = BaseStoredDevice(value.uuid, "DEV${value.deviceType.name}", value.deviceType.color.value);
baseStoredDevice.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);
}
context.pop();
},
);
}
},
dropdownMenuEntries: DeviceRegistry.allDevices.map((e) => DropdownMenuEntry(value: e, label: e.btName)).toList(),
),
),
ListTile(
title: const Text("Remove demo gear"),
leading: const Icon(Icons.delete),
onTap: () {
ref.read(knownDevicesProvider).removeWhere((key, value) => key.contains("DEV"));
ref.read(knownDevicesProvider.notifier).remove(""); // force update
if (ref
.read(knownDevicesProvider)
.values
.where(
(element) => element.deviceConnectionState.value == ConnectivityState.connected,
)
.isEmpty) {
isAnyGearConnected.value = false;
}
},
),
]
],
);
} else {
Expand Down
58 changes: 0 additions & 58 deletions lib/Frontend/pages/developer/developer_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import 'package:go_router/go_router.dart';
import 'package:logging_flutter/logging_flutter.dart';
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';

class DeveloperMenu extends ConsumerStatefulWidget {
Expand Down Expand Up @@ -49,12 +46,6 @@ class _DeveloperMenuState extends ConsumerState<DeveloperMenu> {
throw Exception('Sentry Test');
},
),
ListTile(
title: Text(
"Internal Settings Debug",
style: Theme.of(context).textTheme.titleLarge,
),
),
ListTile(
title: const Text(hasCompletedOnboarding),
trailing: Switch(
Expand Down Expand Up @@ -122,55 +113,6 @@ class _DeveloperMenuState extends ConsumerState<DeveloperMenu> {
},
),
),
ListTile(
title: Text(
"Gear Debug",
style: Theme.of(context).textTheme.titleLarge,
),
),
ListTile(
title: const Text("Add new Device"),
leading: const Icon(Icons.add),
trailing: DropdownMenu<BaseDeviceDefinition>(
initialSelection: null,
onSelected: (value) {
if (value != null) {
setState(
() {
BaseStoredDevice baseStoredDevice;
BaseStatefulDevice statefulDevice;
baseStoredDevice = BaseStoredDevice(value.uuid, "DEV${value.deviceType.name}", value.deviceType.color.value);
baseStoredDevice.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);
}
},
);
}
},
dropdownMenuEntries: DeviceRegistry.allDevices.map((e) => DropdownMenuEntry(value: e, label: e.btName)).toList(),
),
),
ListTile(
title: const Text("Remove Dev Gear"),
leading: const Icon(Icons.delete),
onTap: () {
ref.read(knownDevicesProvider).removeWhere((key, value) => key.contains("DEV"));
ref.read(knownDevicesProvider.notifier).remove(""); // force update
if (ref
.read(knownDevicesProvider)
.values
.where(
(element) => element.deviceConnectionState.value == ConnectivityState.connected,
)
.isEmpty) {
isAnyGearConnected.value = false;
}
},
),
ListTile(
title: const Text("isAnyGearConnected"),
trailing: Switch(
Expand Down

0 comments on commit d1cfd47

Please sign in to comment.