The core updater classes provide the foundational functionality for all platform-specific updaters. AppUpdater handles update checking and downloading, while BaseUpdater extends it with installation capabilities.
The abstract base class that provides core update functionality including checking for updates, downloading, and event management.
/**
* Abstract base class for all updaters providing core update functionality
*/
abstract class AppUpdater extends EventEmitter<AppUpdaterEvents> {
// Automatic behavior configuration
autoDownload: boolean; // Auto-download when update found (default: true)
autoInstallOnAppQuit: boolean; // Auto-install on app quit (default: true)
autoRunAppAfterInstall: boolean; // Run app after install (default: true)
// Update filtering and channels
allowPrerelease: boolean; // Allow pre-release updates (default: false)
fullChangelog: boolean; // Get complete changelog (default: false)
allowDowngrade: boolean; // Allow version downgrades (default: false)
// Security and installation options
disableWebInstaller: boolean; // Disable web installers (default: false)
disableDifferentialDownload: boolean; // Disable differential downloads (default: false)
// Development configuration
forceDevUpdateConfig: boolean; // Force dev mode config (default: false)
// Runtime properties
readonly currentVersion: SemVer; // Current application version
channel: string | null; // Update channel (get/set)
requestHeaders: OutgoingHttpHeaders | null; // HTTP request headers
logger: Logger | null; // Logger instance (get/set)
readonly signals: UpdaterSignal; // Type-safe event handlers
readonly netSession: Session; // Electron net session
// Advanced configuration
isUpdateSupported: VerifyUpdateSupport; // Custom update support verification
isUserWithinRollout: VerifyUpdateSupport; // Custom rollout verification
previousBlockmapBaseUrlOverride: string | null; // Custom blockmap URL
// Core methods
setFeedURL(options: PublishConfiguration | AllPublishOptions | string): void;
checkForUpdates(): Promise<UpdateCheckResult | null>;
checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise<UpdateCheckResult | null>;
downloadUpdate(cancellationToken?: CancellationToken): Promise<Array<string>>;
getFeedURL(): string | null | undefined; // @deprecated
addAuthHeader(token: string): void;
isUpdaterActive(): boolean;
// Abstract methods (implemented by platform-specific updaters)
abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void;
}Constructor Parameters:
/**
* Protected constructor for AppUpdater
* @param options Publisher configuration options
* @param app Optional custom app adapter (defaults to ElectronAppAdapter)
*/
protected constructor(options: AllPublishOptions | null | undefined, app?: AppAdapter);Usage Examples:
// AppUpdater is abstract, so you'll typically use platform-specific classes
// or the autoUpdater instance, but here's how the API works:
import { NsisUpdater } from "electron-updater";
const updater = new NsisUpdater({
provider: "github",
owner: "your-org",
repo: "your-app"
});
// Configure behavior
updater.autoDownload = false; // Manual download control
updater.allowPrerelease = true; // Include beta releases
updater.logger = console; // Enable logging
// Set custom headers
updater.requestHeaders = {
"User-Agent": "MyApp/1.0.0",
"Authorization": "Bearer " + token
};
// Custom update support logic
updater.isUpdateSupported = async (updateInfo) => {
const osVersion = require("os").release();
return semver.gte(osVersion, updateInfo.minimumSystemVersion || "0.0.0");
};
// Check for updates
const result = await updater.checkForUpdates();
if (result?.isUpdateAvailable) {
await updater.downloadUpdate();
}Extends AppUpdater with installation capabilities and platform-specific installation logic.
/**
* Abstract base class extending AppUpdater with installation capabilities
*/
abstract class BaseUpdater extends AppUpdater {
// Installation control
protected quitAndInstallCalled: boolean;
private quitHandlerAdded: boolean;
// Installation methods
quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void;
install(isSilent?: boolean, isForceRunAfter?: boolean): boolean;
// Protected utility methods
protected spawnSyncLog(cmd: string, args?: string[], env?: {}): string;
protected spawnLog(cmd: string, args?: string[], env?: any, stdio?: StdioOptions): Promise<boolean>;
protected addQuitHandler(): void;
protected get installerPath(): string | null;
// Abstract platform-specific installation
protected abstract doInstall(options: InstallOptions): boolean;
}
interface InstallOptions {
readonly isSilent: boolean; // Install without user interaction
readonly isForceRunAfter: boolean; // Force run after installation
readonly isAdminRightsRequired: boolean; // Requires administrator privileges
}Constructor Parameters:
/**
* Protected constructor for BaseUpdater
* @param options Publisher configuration options
* @param app Optional custom app adapter
*/
protected constructor(options?: AllPublishOptions | null, app?: AppAdapter);Usage Examples:
import { AppImageUpdater } from "electron-updater";
const updater = new AppImageUpdater({
provider: "generic",
url: "https://updates.example.com"
});
// Set up automatic installation on quit
updater.autoInstallOnAppQuit = true;
updater.on("update-downloaded", () => {
// Show user notification
showUpdateReadyNotification();
// Install immediately (or let it install on quit)
updater.quitAndInstall();
});
// Manual installation without quitting
updater.on("update-downloaded", () => {
const installed = updater.install(true, false); // silent install, don't force run
if (installed) {
console.log("Update installed successfully");
}
});A logger implementation that ignores all log messages, useful for disabling logging.
/**
* Logger implementation that ignores all messages
*/
class NoOpLogger implements Logger {
info(message?: any): void; // No-op
warn(message?: any): void; // No-op
error(message?: any): void; // No-op
}Usage Examples:
import { autoUpdater, NoOpLogger } from "electron-updater";
// Disable all logging
autoUpdater.logger = new NoOpLogger();
// Or simply set to null
autoUpdater.logger = null;
// Re-enable with console logging
autoUpdater.logger = console;
// Use custom logger
autoUpdater.logger = {
info: (msg) => myLogger.info("Updater:", msg),
warn: (msg) => myLogger.warn("Updater:", msg),
error: (msg) => myLogger.error("Updater:", msg),
debug: (msg) => myLogger.debug("Updater:", msg)
};The updater classes follow a predictable event lifecycle:
// 1. Start checking
autoUpdater.emit("checking-for-update");
// 2a. Update available
autoUpdater.emit("update-available", updateInfo);
if (autoDownload) {
// 3a. Download progress
autoUpdater.emit("download-progress", progressInfo);
// 4a. Download complete
autoUpdater.emit("update-downloaded", downloadedEvent);
}
// 2b. No update available
autoUpdater.emit("update-not-available", updateInfo);
// Error handling at any stage
autoUpdater.emit("error", error, message);
// Cancellation
autoUpdater.emit("update-cancelled", updateInfo);import { autoUpdater, CancellationToken } from "electron-updater";
// Custom cancellation token
const cancellationToken = new CancellationToken();
const downloadPromise = autoUpdater.downloadUpdate(cancellationToken);
// Cancel download after 30 seconds
setTimeout(() => {
cancellationToken.cancel();
}, 30000);
// Custom verification functions
autoUpdater.isUpdateSupported = async (updateInfo) => {
// Check system requirements
const hasRequiredFeatures = await checkSystemFeatures();
const meetsMinVersion = checkMinimumVersion(updateInfo.minimumSystemVersion);
return hasRequiredFeatures && meetsMinVersion;
};
// Staged rollout logic
autoUpdater.isUserWithinRollout = async (updateInfo) => {
const userId = await getUserId();
const userHash = hashUserId(userId);
const rolloutPercentage = updateInfo.stagingPercentage || 100;
return (userHash % 100) < rolloutPercentage;
};
// Custom request headers for authentication
autoUpdater.setFeedURL({
provider: "generic",
url: "https://api.example.com/updates"
});
autoUpdater.requestHeaders = {
"Authorization": `Bearer ${getApiToken()}`,
"X-Client-Version": app.getVersion(),
"X-Platform": process.platform
};