@@ -44,38 +44,40 @@ Future<List<FWInfo>?> getBaseFirmwareInfo(Ref ref, String url) async {
4444 return Response (requestOptions: RequestOptions (), statusCode: 500 );
4545 });
4646 Response <String > value = await valueFuture;
47+ List <FWInfo > results = [];
4748 if (value.statusCode! < 400 ) {
48- return (const JsonDecoder ().convert (value.data.toString ()) as List ).map (
49- (e) {
50- return FWInfo .fromJson (e);
51- },
52- ).toList ();
49+ results = (const JsonDecoder ().convert (value.data.toString ()) as List ).map ((e) {
50+ return FWInfo .fromJson (e);
51+ }).toList ();
5352 }
54- return null ;
53+ return results ;
5554}
5655
57- @Riverpod ()
56+ @Riverpod (keepAlive : true )
5857Future <FWInfo ?> getFirmwareInfo (Ref ref, String url, String hwVer) async {
5958 if (url.isEmpty || hwVer.isEmpty) {
6059 return null ;
6160 }
62- List <FWInfo >? fwInfos = await ref.read (getBaseFirmwareInfoProvider (url).future);
61+
62+ // https://github.com/rrousselGit/riverpod/issues/3745
63+ // using ref.read(provider.future) causes an infinite await on riverpod 3.0
64+
65+ final fwInfosListener = ref.listen (getBaseFirmwareInfoProvider (url).future, (p, n) {});
66+ List <FWInfo >? fwInfos;
67+ try {
68+ fwInfos = await fwInfosListener.read ();
69+ } finally {
70+ fwInfosListener.close ();
71+ }
72+
6373 if (fwInfos == null ) {
6474 return null ;
6575 }
6676 if (fwInfos.isNotEmpty) {
6777 // Find a FW file that matches the gear hardware version
68- FWInfo ? fwInfo = fwInfos.firstWhereOrNull (
69- (element) =>
70- element.supportedHardwareVersions.firstWhereOrNull (
71- (element) => element.trim ().toUpperCase () == hwVer.trim ().toUpperCase (),
72- ) !=
73- null ,
74- );
78+ FWInfo ? fwInfo = fwInfos.firstWhereOrNull ((element) => element.supportedHardwareVersions.firstWhereOrNull ((element) => element.trim ().toUpperCase () == hwVer.trim ().toUpperCase ()) != null );
7579 // Fall back to a generic file if it exists
76- fwInfo ?? = fwInfos.firstWhereOrNull (
77- (element) => element.supportedHardwareVersions.isEmpty,
78- );
80+ fwInfo ?? = fwInfos.firstWhereOrNull ((element) => element.supportedHardwareVersions.isEmpty);
7981 if (fwInfo != null ) {
8082 //check that the app supports this firmware version
8183 Version minimumAppVersion = getVersionSemVer (fwInfo.minimumAppVersion);
@@ -135,27 +137,9 @@ Future<bool> hasOtaUpdate(Ref ref, BaseStatefulDevice baseStatefulDevice) async
135137 return false ;
136138}
137139
138- enum OtaState {
139- standby,
140- download,
141- upload,
142- error,
143- manual,
144- completed,
145- lowBattery,
146- rebooting,
147- }
140+ enum OtaState { standby, download, upload, error, manual, completed, lowBattery, rebooting }
148141
149- enum OtaError {
150- md5Mismatch,
151- downloadFailed,
152- gearVersionMismatch,
153- gearReturnedError,
154- uploadFailed,
155- gearReconnectTimeout,
156- gearDisconnectTimeout,
157- gearOtaFinalTimeout,
158- }
142+ enum OtaError { md5Mismatch, downloadFailed, gearVersionMismatch, gearReturnedError, uploadFailed, gearReconnectTimeout, gearDisconnectTimeout, gearOtaFinalTimeout }
159143
160144@Riverpod ()
161145class OtaUpdater extends _$OtaUpdater {
@@ -320,14 +304,11 @@ class OtaUpdater extends _$OtaUpdater {
320304 if (OtaState .rebooting == state) {
321305 if (connectivityState == ConnectivityState .disconnected) {
322306 _disconnectTimer? .cancel ();
323- _reconnectTimer = Timer (
324- const Duration (seconds: 30 ),
325- () {
326- _otaLogger.warning ("Gear did not reconnect" );
327- _onError (OtaError .gearReconnectTimeout, transaction);
328- transaction? .finish ();
329- },
330- );
307+ _reconnectTimer = Timer (const Duration (seconds: 30 ), () {
308+ _otaLogger.warning ("Gear did not reconnect" );
309+ _onError (OtaError .gearReconnectTimeout, transaction);
310+ transaction? .finish ();
311+ });
331312 } else if (connectivityState == ConnectivityState .connected) {
332313 _reconnectTimer? .cancel ();
333314 }
@@ -379,30 +360,27 @@ class OtaUpdater extends _$OtaUpdater {
379360 if (uploadProgress == 1 ) {
380361 _otaLogger.info ("File Uploaded" );
381362 state = OtaState .rebooting;
382- _disconnectTimer = Timer (
383- const Duration (seconds: 30 ),
384- () {
385- _otaLogger.warning ("Gear did not disconnect" );
386- _onError (OtaError .gearDisconnectTimeout, transaction);
387- transaction? .finish ();
388- },
389- );
363+ _disconnectTimer = Timer (const Duration (seconds: 30 ), () {
364+ _otaLogger.warning ("Gear did not disconnect" );
365+ _onError (OtaError .gearDisconnectTimeout, transaction);
366+ transaction? .finish ();
367+ });
390368 // start scanning for the gear to reconnect
391- _finalTimer = Timer (
392- const Duration (seconds: 60 ),
393- () {
394- if (state != OtaState .completed) {
395- _otaLogger.warning ("Gear did not return correct version after reboot" );
396- _onError (OtaError .gearOtaFinalTimeout, transaction);
397- transaction? .finish ();
398- }
369+ _finalTimer = Timer (const Duration (seconds: 60 ), () {
370+ if (state != OtaState .completed) {
371+ _otaLogger.warning ("Gear did not return correct version after reboot" );
372+ _onError (OtaError .gearOtaFinalTimeout, transaction);
373+ transaction? .finish ();
374+ }
375+ });
376+ analyticsEvent (
377+ name: "Update Gear" ,
378+ props: {
379+ "Target Gear" : baseStatefulDevice.baseDeviceDefinition.btName,
380+ "Hardware Version" : baseStatefulDevice.hwVersion.value,
381+ "Firmware Version" : baseStatefulDevice.fwVersion.value.toString (),
399382 },
400383 );
401- analyticsEvent (name: "Update Gear" , props: {
402- "Target Gear" : baseStatefulDevice.baseDeviceDefinition.btName,
403- "Hardware Version" : baseStatefulDevice.hwVersion.value,
404- "Firmware Version" : baseStatefulDevice.fwVersion.value.toString ()
405- });
406384 }
407385 baseStatefulDevice.deviceState.value = DeviceState .standby; // release the command queue
408386 }
0 commit comments