A drop-in module that adds autoUpdating capabilities to Electron apps
npx @tessl/cli install tessl/npm-update-electron-app@3.1.0Update Electron App is a drop-in module that adds autoUpdating capabilities to Electron applications. It provides seamless integration with minimal configuration, supporting multiple update sources including the free update.electronjs.org service and static file storage solutions like S3.
npm install update-electron-appimport { updateElectronApp, makeUserNotifier, UpdateSourceType } from "update-electron-app";For CommonJS:
const { updateElectronApp, makeUserNotifier, UpdateSourceType } = require("update-electron-app");Note: This package is designed for use within Electron applications, so Electron types (like Electron.Event) are available in the runtime environment.
import { updateElectronApp, UpdateSourceType } from "update-electron-app";
// Simple setup with default configuration
updateElectronApp();
// Custom configuration with update.electronjs.org
updateElectronApp({
updateSource: {
type: UpdateSourceType.ElectronPublicUpdateService,
repo: 'owner/repo'
},
updateInterval: '1 hour',
notifyUser: true
});
// Static storage configuration
updateElectronApp({
updateSource: {
type: UpdateSourceType.StaticStorage,
baseUrl: 'https://my-bucket.s3.amazonaws.com/my-app-updates'
}
});Update Electron App is built around several key components:
Main function to enable auto-updating for Electron applications.
/**
* Enables auto-updating for Electron applications
* @param opts - Configuration options for the updater
*/
function updateElectronApp(opts: IUpdateElectronAppOptions = {}): void;
interface IUpdateElectronAppOptions<L = ILogger> {
/** @deprecated Use updateSource instead */
readonly repo?: string;
/** @deprecated Use updateSource instead */
readonly host?: string;
/** Update source configuration */
readonly updateSource?: IUpdateSource;
/** How frequently to check for updates. Defaults to '10 minutes'. Minimum allowed is '5 minutes' */
readonly updateInterval?: string;
/** Custom logger object. Defaults to console */
readonly logger?: L;
/** Whether to notify user when updates are available. Defaults to true */
readonly notifyUser?: boolean;
/** Custom callback for user notification. Only runs if notifyUser is true */
readonly onNotifyUser?: (info: IUpdateInfo) => void;
}Helper function to create customizable user notification dialogs.
/**
* Creates a callback function for customizing user notification dialogs
* @param dialogProps - Customizable text for the dialog
* @returns Callback function for handling update notifications
*/
function makeUserNotifier(dialogProps?: IUpdateDialogStrings): (info: IUpdateInfo) => void;
interface IUpdateDialogStrings {
/** Dialog title. Defaults to 'Application Update' */
title?: string;
/** Dialog message. Defaults to 'A new version has been downloaded. Restart the application to apply the updates.' */
detail?: string;
/** Restart button text. Defaults to 'Restart' */
restartButtonText?: string;
/** Later button text. Defaults to 'Later' */
laterButtonText?: string;
}Configuration for different update source types.
enum UpdateSourceType {
ElectronPublicUpdateService,
StaticStorage
}
interface IElectronUpdateServiceSource {
type: UpdateSourceType.ElectronPublicUpdateService;
/** GitHub repository in format 'owner/repo'. Defaults to package.json repository field */
repo?: string;
/** Base HTTPS URL of update server. Defaults to 'https://update.electronjs.org' */
host?: string;
}
interface IStaticUpdateSource {
type: UpdateSourceType.StaticStorage;
/** Base URL for static storage provider where updates are stored */
baseUrl: string;
}
type IUpdateSource = IElectronUpdateServiceSource | IStaticUpdateSource;Data structures for update information and logging.
interface IUpdateInfo {
event: Electron.Event;
releaseNotes: string;
releaseName: string;
releaseDate: Date;
updateURL: string;
}
interface ILogger {
log(message: string): void;
info(message: string): void;
error(message: string): void;
warn(message: string): void;
}The library handles various error conditions: