checkNow method
Runs one check → download → prompt cycle. Safe to call any number of times — concurrent calls collapse into the in-flight check, and all failures are caught and reflected in status rather than thrown.
Implementation
Future<void> checkNow() async {
if (_checkInFlight) return;
_checkInFlight = true;
try {
_setStatus('Checking for updates…');
final result =
await _codePush.checkForUpdate(channel: widget.config.channel);
switch (result) {
case UpdateStatus.outdated:
_setStatus('Downloading patch…');
try {
await _codePush.update(channel: widget.config.channel);
await _markPatchReady();
} on Exception {
_setStatus('Patch download failed');
}
case UpdateStatus.restartRequired:
await _markPatchReady();
case UpdateStatus.upToDate:
_setStatus('Up to date');
case UpdateStatus.unavailable:
_setStatus('CodePush unavailable');
}
} on Exception {
_setStatus('Update check failed');
} finally {
_checkInFlight = false;
}
}