checkAndRefresh static method
Reloads into a newer build when there is one; asks first unless silent. await UWebUpdate.checkAndRefresh()
Implementation
static Future<bool> checkAndRefresh({
bool silent = false,
bool once = true,
bool bustUrl = false,
String? title,
String? message,
String? confirmText,
String? cancelText,
}) async {
if (!UApp.isWeb || _checking) return false;
_checking = true;
try {
if (!await hasUpdate()) return false;
final String signature = (await serverBuild())?.signature ?? "";
final bool guarded = once && signature.isNotEmpty;
if (guarded && ULocalStorage.getString(_refreshedBuildKey) == signature) return false;
if (!silent) {
if (guarded && ULocalStorage.getString(_declinedBuildKey) == signature) return false;
// No navigator yet, so there is nobody to ask; leave the build untouched and retry later.
if (navigatorKey.currentContext == null) return false;
final bool accepted = await UNavigator.confirmAsync(
title: title ?? U.s.updateAvailable,
message: message ?? U.s.aNewVersionIsAvailableReloadToGetIt,
confirmText: confirmText ?? U.s.refresh,
cancelText: cancelText ?? U.s.later,
icon: Icons.system_update_alt_rounded,
);
if (!accepted) {
if (signature.isNotEmpty) ULocalStorage.set(_declinedBuildKey, signature);
return false;
}
}
if (signature.isNotEmpty) ULocalStorage.set(_refreshedBuildKey, signature);
await refresh(bustUrl: bustUrl);
return true;
} finally {
_checking = false;
}
}