Skip to content

Commit

Permalink
add retry to gear connect
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Nov 24, 2024
1 parent f8f72b7 commit c55e83c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Backend/Bluetooth/bluetooth_manager_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,13 @@ Future<void> connect(String id) async {
ScanResult? result = results.where((element) => element.device.remoteId.str == id).firstOrNull;
if (result != null) {
int retry = 0;
while (retry < 3) {
while (retry < HiveProxy.getOrDefault(settings, gearConnectRetryAttempts, defaultValue: gearConnectRetryAttemptsDefault)) {
try {
await result.device.connect();
break;
} on FlutterBluePlusException catch (e) {
retry = retry + 1;
_bluetoothPlusLogger.warning("Failed to connect to ${result.device.advName}. Attempt $retry/3", e);
_bluetoothPlusLogger.warning("Failed to connect to ${result.device.advName}. Attempt $retry/${HiveProxy.getOrDefault(settings, gearConnectRetryAttempts, defaultValue: gearConnectRetryAttemptsDefault)}", e);
await Future.delayed(Duration(milliseconds: 250));
}
}
Expand Down
15 changes: 15 additions & 0 deletions lib/Frontend/pages/developer/developer_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ class _DeveloperMenuState extends ConsumerState<DeveloperMenu> {
},
),
),
ListTile(
title: const Text(gearConnectRetryAttempts),
subtitle: Slider(
divisions: 29,
max: 30,
min: 1,
label: HiveProxy.getOrDefault(settings, gearConnectRetryAttempts, defaultValue: gearConnectRetryAttemptsDefault).toString(),
value: HiveProxy.getOrDefault(settings, gearConnectRetryAttempts, defaultValue: gearConnectRetryAttemptsDefault).toDouble(),
onChanged: (double value) async {
setState(() {
HiveProxy.put(settings, gearConnectRetryAttempts, value.toInt());
});
},
),
),
ListTile(
title: const Text(showDebugging),
trailing: Switch(
Expand Down
2 changes: 2 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const String casualModeDelayMin = 'casualModeDelayMin';
const String casualModeDelayMax = 'casualModeDelayMax';
const String tailBlogWifiOnly = 'tailBlogWifiOnly';
const String triggerActionCooldown = 'triggerActionCooldown';
const String gearConnectRetryAttempts = 'gearConnectRetryAttempts';

// Settings Default value
const bool kitsuneModeDefault = false;
Expand All @@ -55,6 +56,7 @@ const int casualModeDelayMinDefault = 15;
const int casualModeDelayMaxDefault = 120;
const bool tailBlogWifiOnlyDefault = false;
const int triggerActionCooldownDefault = 15;
const int gearConnectRetryAttemptsDefault = 3;

const String triggerBox = 'triggers';
const String sequencesBox = 'sequences';
Expand Down

0 comments on commit c55e83c

Please sign in to comment.