@todesktop/updater
v0.1.1
Published
ToDesktop's updater for Electron and other Node apps: a Node-API addon, plus the todesktop-updater sidecar
Readme
@todesktop/updater
ToDesktop's updater for Electron apps (and other Node apps) that ToDesktop
builds: it checks for updates, verifies them against the signed release,
downloads them and puts them in place, following the update policy in your
todesktop.ts. A Node-API addon; npm installs the build for your platform
(macOS universal, Linux x64 and arm64 with glibc 2.28 or later, Windows x64 and
arm64) from an optional dependency, with the todesktop-updater sidecar beside
it.
Proprietary: see LICENSE.
Electron
npm install @todesktop/updaterIn the main process, before anything else:
const { app } = require('electron');
const { requestedHook, startUpdates } = require('@todesktop/updater/electron');
// Started by the installer or uninstaller for a lifecycle hook: do it, exit.
if (requestedHook()) app.exit(0);
app.whenReady().then(() => {
const updates = startUpdates(app);
updates.onChange((state) => {
// idle, checking, available, downloading, ready, error, blocked, managed
if (state.status === 'ready') updates.restart();
});
});startUpdates(app) runs your build's policy (when to check, download and
install); restart() quits through app.quit(), so your shutdown code runs,
and the new version starts after the app exits. Builds that ToDesktop didn't
make (electron .) have no identity: updates stay off and say why. Types are in
index.d.cts.
The sidecar
Updates the app can't do while it runs (replacing a macOS app bundle after it
quits) are finished by todesktop-updater, which is also the helper that asks
for an administrator when the app is installed where the user can't write. The
updater looks for it beside the app's executable: Contents/MacOS on macOS,
beside YourApp.exe on Windows and the executable on Linux.
Without one there,
startUpdates()uses the copy from the npm package, which must be outside the asar: unpack the platform package (electron-builder unpacks it by itself; with Electron Forge addasar: { unpack: '**/node_modules/@todesktop/updater-*/**' }).For installs that need an administrator to update (a macOS app in
/Applicationsowned by another user, say), copy it beside the executable. With electron-builder:{ "asarUnpack": ["node_modules/@todesktop/updater-*/**"], "mac": { "extraFiles": [ { "from": "node_modules/@todesktop/updater-darwin-universal/todesktop-updater", "to": "MacOS/todesktop-updater" } ] }, "win": { "extraFiles": [ { "from": "node_modules/@todesktop/updater-win32-${arch}-msvc/todesktop-updater.exe", "to": "todesktop-updater.exe" } ] }, "linux": { "extraFiles": [ { "from": "node_modules/@todesktop/updater-linux-${arch}-gnu/todesktop-updater", "to": "todesktop-updater" } ] } }(
${arch}isx64orarm64.)require('@todesktop/updater/electron').sidecarPath()says which copy the app uses.
Ship it unsigned: ToDesktop signs it with your certificate along with the rest
of the app, and refuses a Windows build whose todesktop-updater.exe isn't the
hardened one from this package.
Other Node apps
const { Updates } = require('@todesktop/updater');
const updates = Updates.fromCurrentExe(); // or Updates.fromAppDir(dir)
updates.start();Versions
The package's version is the ToDesktop runtime version, shared with the
todesktop-updater and
tauri-plugin-todesktop
crates; the updater sends it with every request (x-td-runtime-version).
ToDesktop's servers keep working with every runtime version.
