checkAndUpdate function
Checks if a new version is available on pub.dev and installs it.
Returns true if an update was installed and the worker should restart
(exit with exitCodeUpdateRequested).
Uses dart pub global activate to install the new version.
The supervisor will restart the worker process automatically.
Implementation
Future<bool> checkAndUpdate() async {
try {
final latestVersion = await _fetchLatestVersion();
if (latestVersion == null) return false;
if (latestVersion == version) {
_log.fine('Already on latest version ($version)');
return false;
}
if (!_isNewerVersion(latestVersion, version)) {
_log.fine('Remote version ($latestVersion) is not newer than $version');
return false;
}
_log.info('New version available: $version → $latestVersion');
return await _installUpdate(latestVersion);
} catch (e) {
_log.warning('Auto-update check failed: $e');
return false;
}
}