Skip to content

Commit f3eae98

Browse files
authored
Extend the ble reconnection interval to 7s (#2287)
1 parent 45725f0 commit f3eae98

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

app/lib/providers/device_provider.dart

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
2727
int batteryLevel = -1;
2828
bool _hasLowBatteryAlerted = false;
2929
Timer? _reconnectionTimer;
30-
int connectionCheckSeconds = 7;
3130
DateTime? _reconnectAt;
31+
final int _connectionCheckSeconds = 7;
3232

3333
bool _havingNewFirmware = false;
3434
bool get havingNewFirmware => _havingNewFirmware && pairedDevice != null && isConnected;
@@ -140,8 +140,8 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
140140

141141
Future periodicConnect(String printer) async {
142142
_reconnectionTimer?.cancel();
143-
_reconnectionTimer = Timer.periodic(Duration(seconds: connectionCheckSeconds), (t) async {
144-
debugPrint("Period connect seconds: $connectionCheckSeconds, triggered timer at ${DateTime.now()}");
143+
_reconnectionTimer = Timer.periodic(Duration(seconds: _connectionCheckSeconds), (t) async {
144+
debugPrint("Period connect seconds: $_connectionCheckSeconds, triggered timer at ${DateTime.now()}");
145145
if (SharedPreferencesUtil().btDevice.id.isEmpty) {
146146
t.cancel();
147147
return;
@@ -186,30 +186,31 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
186186
if (isConnected) {
187187
if (connectedDevice == null) {
188188
connectedDevice = await _getConnectedDevice();
189-
// SharedPreferencesUtil().btDevice = connectedDevice!;
190189
SharedPreferencesUtil().deviceName = connectedDevice!.name;
191190
MixpanelManager().deviceConnected();
192191
}
193192

194193
setIsConnected(true);
195194
updateConnectingStatus(false);
196-
} else {
197-
var device = await _scanAndConnectDevice();
198-
print('inside scanAndConnectToDevice $device in device_provider');
199-
if (device != null) {
200-
var cDevice = await _getConnectedDevice();
201-
if (cDevice != null) {
202-
setConnectedDevice(cDevice);
203-
setIsDeviceV2Connected();
204-
// SharedPreferencesUtil().btDevice = cDevice;
205-
SharedPreferencesUtil().deviceName = cDevice.name;
206-
MixpanelManager().deviceConnected();
207-
setIsConnected(true);
208-
}
209-
print('device is not null $cDevice');
195+
notifyListeners();
196+
return;
197+
}
198+
199+
// else
200+
var device = await _scanAndConnectDevice();
201+
debugPrint('inside scanAndConnectToDevice $device in device_provider');
202+
if (device != null) {
203+
var cDevice = await _getConnectedDevice();
204+
if (cDevice != null) {
205+
setConnectedDevice(cDevice);
206+
setIsDeviceV2Connected();
207+
SharedPreferencesUtil().deviceName = cDevice.name;
208+
MixpanelManager().deviceConnected();
209+
setIsConnected(true);
210210
}
211-
updateConnectingStatus(false);
211+
debugPrint('device is not null $cDevice');
212212
}
213+
updateConnectingStatus(false);
213214

214215
notifyListeners();
215216
}
@@ -222,10 +223,7 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
222223
void setIsConnected(bool value) {
223224
isConnected = value;
224225
if (isConnected) {
225-
connectionCheckSeconds = 8;
226226
_reconnectionTimer?.cancel();
227-
} else {
228-
connectionCheckSeconds = 4;
229227
}
230228
notifyListeners();
231229
}

0 commit comments

Comments
 (0)