Skip to content

Latest commit

 

History

History
75 lines (56 loc) · 2.14 KB

File metadata and controls

75 lines (56 loc) · 2.14 KB

Updater

app.updater checks for, downloads, and applies updates to compiled binaries.

check

const update = await app.updater.check({
  currentVersion: app.info().version,
  source: { type: "github", repo: "owner/repo", asset: process.platform === "win32" ? /\.exe$/ : /linux/ },
});

if (update.hasUpdate) {
  console.log(`update available: ${update.version}`);
  console.log(update.notes);
}

source can be:

  • { type: "github", repo: "owner/repo", prerelease?, asset } - checks the latest (or latest pre-release, if prerelease: true) GitHub release. asset selects which release asset to use: a RegExp, a string (substring match), or a function (asset) => boolean.
  • { type: "manifest", url: "https://example.com/update.json" } - fetches a JSON manifest from a URL.
  • { type: "file", path: "./update.json" } - reads a local JSON manifest.

Manifest/file sources look like:

{ "version": "1.2.3", "url": "https://example.com/downloads/app-linux", "notes": "Bug fixes" }

url may be http(s)://, a local filesystem path, or file://.

The result is { version, url, notes, currentVersion, hasUpdate }, where hasUpdate is true if version is newer than currentVersion.

download

const file = await app.updater.download(update, "./update-download");
// file: path to the downloaded binary

Downloads update.url to dir (created if needed), reporting progress is not built in - call this when you're ready to fetch the new binary.

apply

app.updater.apply(file);

Replaces the currently running binary with file and restarts the app. Compiled builds only - this is a no-op (or throws) when run via bun run, since there's no standalone binary to replace.

Typical flow

const update = await app.updater.check({ currentVersion: app.info().version, source: { /* ... */ } });

if (update.hasUpdate) {
  const ok = await app.dialog.confirm({
    title: "Update available",
    message: `Version ${update.version} is available. Update now?`,
  });
  if (ok) {
    const file = await app.updater.download(update, app.paths.userCache());
    app.updater.apply(file);
  }
}