Skip to content

Commit

Permalink
catch some update check errors
Browse files Browse the repository at this point in the history
also changes mandatory ota check
  • Loading branch information
Codel1417 committed Dec 22, 2024
1 parent 89feb35 commit 757a6d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 9 additions & 2 deletions lib/Backend/Bluetooth/bluetooth_manager_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ class _OnCharacteristicReceived extends _$OnCharacteristicReceived {
),
);
}
await ref.read(hasOtaUpdateProvider(statefulDevice).future);
// Don't check for updates unless both values are set
if (statefulDevice.hwVersion.value.isNotEmpty && statefulDevice.fwVersion.value != Version()) {
await ref.read(hasOtaUpdateProvider(statefulDevice).future).catchError((error, stackTrace) => true);
}
// Sent after VER message
} else if (value.startsWith("GLOWTIP")) {
String substring = value.substring(value.indexOf(" ")).trim();
Expand All @@ -381,7 +384,11 @@ class _OnCharacteristicReceived extends _$OnCharacteristicReceived {
} else if (value.contains("HWVER") || value.contains("MITAIL") || value.contains("MINITAIL") || value.contains("FLUTTERWINGS")) {
// Hardware Version
statefulDevice.hwVersion.value = value.substring(value.indexOf(" "));
await ref.read(hasOtaUpdateProvider(statefulDevice).future);
// Don't check for updates unless both values are set
if (statefulDevice.hwVersion.value.isNotEmpty && statefulDevice.fwVersion.value != Version()) {
await ref.read(hasOtaUpdateProvider(statefulDevice).future).catchError((error, stackTrace) => true);
}
;
} else if (int.tryParse(value) != null) {
// Battery Level
statefulDevice.batteryLevel.value = int.parse(value).toDouble();
Expand Down
13 changes: 9 additions & 4 deletions lib/Backend/firmware_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ Future<FWInfo?> checkForFWUpdate(Ref ref, BaseStatefulDevice baseStatefulDevice)
}
String hwVer = baseStatefulDevice.hwVersion.value;
if (hwVer.isEmpty) {
ref.invalidateSelf();
return null;
throw Exception("Hardware Version from gear is unknown");
}
FWInfo? fwInfo = await ref.read(getFirmwareInfoProvider(url, hwVer).future);
baseStatefulDevice.fwInfo.value = fwInfo;
Expand All @@ -113,16 +112,22 @@ Future<bool> hasOtaUpdate(Ref ref, BaseStatefulDevice baseStatefulDevice) async

// Check if fw version is not set (0.0.0)
if (baseStatefulDevice.fwVersion.value == const Version()) {
return false;
throw Exception("Version from gear is unknown");
}
// check if firmware info from firmware is set and is greater than (0.0.0)
if (fwInfo == null || fwVersion.compareTo(const Version()) <= 0) {
return false;
throw Exception("Version from gear or server is unavailable");
}

// Check that the firmware from the server is greater than the firmware on device
if (fwVersion.compareTo(getVersionSemVer(fwInfo.version)) < 0) {
baseStatefulDevice.hasUpdate.value = true;
// handle if the update is mandatory for app functionality
if (baseStatefulDevice.baseDeviceDefinition.minVersion != null) {
if (fwVersion.compareTo(baseStatefulDevice.baseDeviceDefinition.minVersion!) < 0) {
baseStatefulDevice.mandatoryOtaRequired.value = true;
}
}
return true;
}
return false;
Expand Down

0 comments on commit 757a6d0

Please sign in to comment.