Skip to content

Commit

Permalink
Remove auto connect to new gear
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Mar 4, 2024
1 parent 9085011 commit bdc625d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 48 deletions.
69 changes: 23 additions & 46 deletions lib/Frontend/Widgets/scan_for_new_device.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import 'dart:async';

import 'package:animate_do/animate_do.dart';
import 'package:flutter/material.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Backend/Definitions/Device/BaseDeviceDefinition.dart';

import '../../Backend/Bluetooth/BluetoothManager.dart';
Expand Down Expand Up @@ -35,54 +32,34 @@ class _ScanForNewDevice extends ConsumerState<ScanForNewDevice> {
if (foundDevices.valueOrNull != null) {
DiscoveredDevice? value = foundDevices.valueOrNull;
if (value != null && !devices.containsKey(value.id)) {
if (SentryHive.box('settings').get('autoConnectNewDevices', defaultValue: false)) {
Future(() => ref.read(knownDevicesProvider.notifier).connect(value));
} else {
devices[value.id] = value;
}
devices[value.id] = value;
}
}
return Column(
children: [
ListTile(
dense: true,
trailing: Switch(
onChanged: (bool value) {
setState(() {
SentryHive.box('settings').put('autoConnectNewDevices', value);
});
},
value: SentryHive.box('settings').get('autoConnectNewDevices', defaultValue: false),
),
title: Text(scanDevicesAutoConnectTitle()),
),
Wrap(
children: [
ListView.builder(
shrinkWrap: true,
itemCount: devices.values.length,
itemBuilder: (BuildContext context, int index) {
DiscoveredDevice e = devices.values.toList()[index];
return FadeIn(
delay: const Duration(milliseconds: 100),
child: ListTile(
title: Text(getNameFromBTName(e.name)),
trailing: Text(e.id),
onTap: () {
ref.watch(knownDevicesProvider.notifier).connect(e);
plausible.event(name: "Connect New Gear", props: {"Type": e.name});
setState(
() {
devices.remove(e.id);
},
);
Navigator.pop(context);
ListView.builder(
shrinkWrap: true,
itemCount: devices.values.length,
itemBuilder: (BuildContext context, int index) {
DiscoveredDevice e = devices.values.toList()[index];
return FadeIn(
delay: const Duration(milliseconds: 100),
child: ListTile(
title: Text(getNameFromBTName(e.name)),
trailing: Text(e.id),
onTap: () {
ref.watch(knownDevicesProvider.notifier).connect(e);
plausible.event(name: "Connect New Gear", props: {"Type": e.name});
setState(
() {
devices.remove(e.id);
},
),
);
},
),
],
);
Navigator.pop(context);
},
),
);
},
),
Padding(
padding: const EdgeInsets.only(top: 20),
Expand Down
2 changes: 0 additions & 2 deletions lib/Frontend/intnDefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ String manageDevicesForget() => Intl.message('Forget', name: 'manageDevicesForge

String manageDevicesOtaButton() => Intl.message('Tap to update firmware', name: 'manageDevicesOtaButton', desc: 'manage devices ota available button');

String scanDevicesAutoConnectTitle() => Intl.message('Automatically connect to new devices', name: 'scanDevicesAutoConnectTitle', desc: 'scan for devices auto connect toggle title when scanning for a device');

String scanDevicesTitle() => Intl.message('Scan For New Gear', name: 'scanDevicesTitle', desc: 'button which opens the scan window');

String scanDevicesScanMessage() => Intl.message('Scanning for gear. Please make sure your gear is powered on and nearby', name: 'scanDevicesScanMessage', desc: 'scan for devices scan in progress message when scanning for a device');
Expand Down

0 comments on commit bdc625d

Please sign in to comment.