updater

Tell people a new version is ready and update the app in place, on the web, desktop and mobile.

PlatformsClient

Every export of kitr/updater, kitr/updater/react, kitr/updater/provider, read from the published type definitions. The guide shows them in use.

kitr/updater

createMemoryUpdaterDriver

function createMemoryUpdaterDriver(options?: {
  version?: string;
  next?: UpdateInfo | null;
}): {
  name: string;
  next: UpdateInfo | null;
  applied: UpdateInfo[];
  check: () => Promise<UpdateInfo | null>;
  apply: (onProgress?: (f: number) => void) => Promise<void>;
  onAvailable(listener: (info: UpdateInfo) => void): () => void;
  announce(info: UpdateInfo): void;
  currentVersion: () => Promise<string>;
};

For tests and the server: set next to simulate an available update.

createServiceWorkerUpdaterDriver

function createServiceWorkerUpdaterDriver(options?: {
  version?: string;
}): UpdaterDriver;

Service-worker driver: an update is "available" when a new worker is waiting; applying reloads.

createUpdater

function createUpdater(config?: UpdaterConfig, app?: KitrApp): Updater;

useUpdater

function useUpdater(app: KitrApp): Updater;

defineConfig

const defineConfig: <const C extends UpdaterConfig>(config: C) => C;

UpdateInfo

interface UpdateInfo {
  version: string;
  notes?: string;
  date?: string;
  /** Bytes, when the driver knows. */
  size?: number;
}

Updater

interface Updater {
  readonly driver: UpdaterDriver;
  readonly state: UpdaterState;
  check(): Promise<UpdateInfo | null>;
  apply(): Promise<void>;
  /** Hide the prompt until the next update. */
  dismiss(): void;
  subscribe(listener: () => void): () => void;
  /** Stop the interval and listeners. */
  stop(): void;
}

UpdaterConfig

interface UpdaterConfig {
  driver?: UpdaterDriver;
  /** Re-check every N milliseconds while the app is open. Default: none (check at boot only). */
  interval?: number;
  /** Check as soon as the app boots. Default true. */
  checkOnBoot?: boolean;
  /** Apply as soon as an update is ready, without asking. Default false. */
  auto?: boolean;
}

UpdaterDriver

interface UpdaterDriver {
  name: string;
  /** Look for a newer version. Resolves to the update or null when current. */
  check(): Promise<UpdateInfo | null>;
  /** Download (when needed) and install. Usually restarts or reloads the app. */
  apply(onProgress?: (fraction: number) => void): Promise<void>;
  /** Called by drivers that learn about updates on their own (service worker, background download). */
  onAvailable?(listener: (info: UpdateInfo) => void): () => void;
  /** Current app version, when known. */
  currentVersion?(): Promise<string>;
}

UpdaterState

interface UpdaterState {
  status: UpdateStatus;
  update: UpdateInfo | null;
  progress: number;
  error: Error | null;
  currentVersion: string | null;
}

UpdateStatus

type UpdateStatus = 'idle' | 'checking' | 'available' | 'downloading' | 'ready' | 'up-to-date' | 'error';

One check/apply flow for new versions. On the web the driver watches the service worker (updatefound → waiting) and applies by telling it to skip waiting and reloading. Desktop packages register the Tauri or Electron updater; mobile ones report the store version or a live-update bundle.

kitr/updater/react

useUpdate

function useUpdate(): {
  available: boolean;
  check: () => Promise<UpdateInfo | null>;
  apply: () => Promise<void>;
  dismiss: () => void;
  status: UpdateStatus;
  update: UpdateInfo | null;
  progress: number;
  error: Error | null;
  currentVersion: string | null;
};

{ status, update, progress, check, apply, dismiss } for an "update ready" banner. Hydration-safe: the server and first render see idle.

useUpdater

function useUpdater(): Updater;

kitr/updater/provider

updaterProvider

const updaterProvider: import("@kitr/core").KitrProvider;

Binds updater to the platform updater (updater capability) or the service-worker driver, checks at boot and on the configured interval, and stops at shutdown.