startWatching static method

void startWatching({
  1. Duration interval = const Duration(minutes: 15),
  2. bool silent = false,
  3. bool checkNow = true,
  4. bool silentOnStart = true,
  5. bool onVisible = true,
  6. bool bustUrl = false,
})

Watches for new builds: once at startup, every interval, and whenever the tab is brought back to the foreground. Safe to call before runApp. End it with stopWatching.

The startup check is silentOnStart because nothing is in flight yet, so reloading costs the user nothing and needs no navigator. Later checks use silent, which defaults to asking first — a reload in the middle of a half-filled form would throw that input away.

Implementation

static void startWatching({
  Duration interval = const Duration(minutes: 15),
  bool silent = false,
  bool checkNow = true,
  bool silentOnStart = true,
  bool onVisible = true,
  bool bustUrl = false,
}) {
  if (!UApp.isWeb) return;
  stopWatching();
  _timer = Timer.periodic(interval, (_) => unawaited(checkAndRefresh(silent: silent, bustUrl: bustUrl)));
  if (onVisible) _visibilityDisposer = UWebBridge.listenVisible(() => unawaited(checkAndRefresh(silent: silent, bustUrl: bustUrl)));
  if (checkNow) unawaited(checkAndRefresh(silent: silentOnStart, bustUrl: bustUrl));
}