Cross platform updater for electron applications with multi-platform support and differential downloads
npx @tessl/cli install tessl/npm-electron-updater@6.6.0Electron Updater is a comprehensive cross-platform auto-update solution for Electron applications that enables seamless application updates without requiring users to manually download and install new versions. It supports multiple update strategies across different operating systems including macOS (using Squirrel.Mac), Windows (using NSIS), and Linux (supporting AppImage, rpm, deb, and pacman formats).
The library offers a simple API that requires only a few lines of code to implement, handles differential downloads for efficient updates, provides code signature verification for security, and supports various hosting solutions including simple file hosting without requiring a dedicated server. The updater is designed for maximum compatibility and ease of use, featuring automatic platform detection, comprehensive error handling, progress reporting, and integration with popular Electron build tools.
npm install electron-updaterimport { autoUpdater, AppUpdater, BaseUpdater } from "electron-updater";For CommonJS:
const { autoUpdater, AppUpdater, BaseUpdater } = require("electron-updater");Platform-specific updaters:
import {
NsisUpdater, // Windows NSIS
MacUpdater, // macOS Squirrel.Mac
AppImageUpdater, // Linux AppImage
DebUpdater, // Linux Debian packages
RpmUpdater, // Linux RPM packages
PacmanUpdater // Linux Pacman packages
} from "electron-updater";Provider classes (imported from individual modules):
import { Provider } from "electron-updater";
import { GenericProvider } from "electron-updater/out/providers/GenericProvider";
import { GitHubProvider } from "electron-updater/out/providers/GitHubProvider";
import { PrivateGitHubProvider } from "electron-updater/out/providers/PrivateGitHubProvider";
import { BitbucketProvider } from "electron-updater/out/providers/BitbucketProvider";
import { GitLabProvider } from "electron-updater/out/providers/GitLabProvider";
import { KeygenProvider } from "electron-updater/out/providers/KeygenProvider";Note: Provider classes are not re-exported from the main module and must be imported from their individual compiled files.
import { autoUpdater } from "electron-updater";
// Configure update provider
autoUpdater.setFeedURL({
provider: "github",
owner: "your-org",
repo: "your-app"
});
// Set up event handlers
autoUpdater.on("checking-for-update", () => {
console.log("Checking for update...");
});
autoUpdater.on("update-available", (info) => {
console.log("Update available:", info.version);
});
autoUpdater.on("update-not-available", (info) => {
console.log("Update not available");
});
autoUpdater.on("error", (err) => {
console.log("Error in auto-updater:", err);
});
autoUpdater.on("download-progress", (progressObj) => {
console.log(`Download progress: ${progressObj.percent}%`);
});
autoUpdater.on("update-downloaded", (info) => {
console.log("Update downloaded");
// Restart the app and install the update
autoUpdater.quitAndInstall();
});
// Check for updates
autoUpdater.checkForUpdates();Electron Updater is built around several key components:
AppUpdater and BaseUpdater provide core functionality that platform-specific updaters extendThe main autoUpdater constant that provides a platform-specific updater instance automatically selected based on the current operating system.
declare const autoUpdater: AppUpdater;Abstract base classes that provide the core update functionality, with AppUpdater handling update checking and downloading, and BaseUpdater adding installation capabilities.
abstract class AppUpdater extends EventEmitter {
autoDownload: boolean;
autoInstallOnAppQuit: boolean;
allowPrerelease: boolean;
channel: string | null;
currentVersion: SemVer;
logger: Logger | null;
setFeedURL(options: PublishConfiguration | AllPublishOptions | string): void;
checkForUpdates(): Promise<UpdateCheckResult | null>;
downloadUpdate(cancellationToken?: CancellationToken): Promise<Array<string>>;
abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void;
}
abstract class BaseUpdater extends AppUpdater {
quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void;
install(isSilent?: boolean, isForceRunAfter?: boolean): boolean;
}Platform-specific updater implementations for different operating systems and package formats.
class NsisUpdater extends BaseUpdater {
installDirectory?: string;
verifyUpdateCodeSignature: VerifyUpdateCodeSignature;
}
class MacUpdater extends BaseUpdater {}
class AppImageUpdater extends BaseUpdater {
isUpdaterActive(): boolean;
}
class DebUpdater extends LinuxUpdater {}
class RpmUpdater extends LinuxUpdater {}
class PacmanUpdater extends LinuxUpdater {}Provider classes for different hosting solutions and update servers.
abstract class Provider<T extends UpdateInfo> {
isUseMultipleRangeRequest: boolean;
fileExtraDownloadHeaders: OutgoingHttpHeaders | null;
setRequestHeaders(value: OutgoingHttpHeaders | null): void;
abstract getLatestVersion(): Promise<T>;
abstract resolveFiles(updateInfo: T): Array<ResolvedUpdateFileInfo>;
}
class GenericProvider extends Provider<UpdateInfo> {}
class GitHubProvider extends Provider<GithubUpdateInfo> {}
class PrivateGitHubProvider extends GitHubProvider {}Core types and interfaces for update information, configuration, and event handling.
interface UpdateInfo {
version: string;
files: UpdateFileInfo[];
releaseName?: string;
releaseNotes?: string;
releaseDate: string;
stagingPercentage?: number;
}
interface UpdateCheckResult {
readonly isUpdateAvailable: boolean;
readonly updateInfo: UpdateInfo;
readonly downloadPromise?: Promise<Array<string>> | null;
readonly cancellationToken?: CancellationToken;
}
interface Logger {
info(message?: any): void;
warn(message?: any): void;
error(message?: any): void;
debug?(message: string): void;
}Comprehensive event system for monitoring the update lifecycle with type-safe event handlers.
class UpdaterSignal {
login(handler: LoginHandler): void;
progress(handler: (info: ProgressInfo) => void): void;
updateDownloaded(handler: (info: UpdateDownloadedEvent) => void): void;
updateCancelled(handler: (info: UpdateInfo) => void): void;
}
type AppUpdaterEvents = {
error: (error: Error, message?: string) => void;
login: (info: AuthInfo, callback: LoginCallback) => void;
"checking-for-update": () => void;
"update-available": (info: UpdateInfo) => void;
"update-not-available": (info: UpdateInfo) => void;
"update-downloaded": (event: UpdateDownloadedEvent) => void;
"download-progress": (info: ProgressInfo) => void;
"update-cancelled": (info: UpdateInfo) => void;
}Configuration options for different hosting providers and update server setups.
interface PublishConfiguration {
provider: "github" | "s3" | "generic" | "bitbucket" | "gitlab" | "keygen" | "custom";
publishAutoUpdate?: boolean;
}
interface GithubOptions extends PublishConfiguration {
provider: "github";
owner: string;
repo: string;
token?: string;
private?: boolean;
releaseType?: "draft" | "prerelease" | "release";
}
interface GenericServerOptions extends PublishConfiguration {
provider: "generic";
url: string;
channel?: string;
useMultipleRangeRequest?: boolean;
}