### Install update-electron-app Source: https://github.com/electron/update-electron-app/blob/main/README.md Install the module using npm. ```sh npm i update-electron-app ``` -------------------------------- ### Initialize Auto-Updates with Minimal Setup Source: https://context7.com/electron/update-electron-app/llms.txt Call this once in your Electron main process for basic setup. It auto-detects the repository from package.json. ```javascript // main.js — Minimal setup using update.electronjs.org (repo auto-detected from package.json) const { updateElectronApp } = require('update-electron-app'); updateElectronApp(); ``` -------------------------------- ### Configure update-electron-app with Custom Logger and Options Source: https://context7.com/electron/update-electron-app/llms.txt Configure the update-electron-app with a custom logger that conforms to the ILogger interface and specify various options like update interval and source. This example demonstrates how to integrate a custom logging mechanism and set detailed update configurations. ```typescript import { updateElectronApp, UpdateSourceType, IUpdateElectronAppOptions, ILogger, } from 'update-electron-app'; // Custom logger compatible with ILogger interface const myLogger: ILogger = { log: (msg) => writeToFile('INFO', msg), info: (msg) => writeToFile('INFO', msg), warn: (msg) => writeToFile('WARN', msg), error: (msg) => writeToFile('ERROR', msg), }; const options: IUpdateElectronAppOptions = { updateSource: { type: UpdateSourceType.ElectronPublicUpdateService, repo: 'acme/desktop-app', }, updateInterval: '20 minutes', // human-readable string parsed by the `ms` package logger: myLogger, notifyUser: true, onNotifyUser: undefined, // set to override the default makeUserNotifier() dialog }; updateElectronApp(options); // Validation rules enforced at runtime: // • updateInterval must be >= 5 minutes and < 2^31 ms // • host / baseUrl must be a valid HTTPS URL (http:// will throw) // • repo must be in "owner/repo" format // • In development (app.isPackaged === false), the call is a no-op // • On Linux, the call is a no-op (autoUpdater not supported) ``` -------------------------------- ### Dynamically Select Update Source using Enum Source: https://context7.com/electron/update-electron-app/llms.txt Use the UpdateSourceType enum to conditionally configure the update source based on environment variables. This example switches between the public service and static storage. ```typescript import { UpdateSourceType } from 'update-electron-app'; // UpdateSourceType.ElectronPublicUpdateService → 0 // UpdateSourceType.StaticStorage → 1 // Use in a conditional to switch sources by environment: const source = process.env.UPDATE_SOURCE === 'static' ? { type: UpdateSourceType.StaticStorage, baseUrl: `https://cdn.example.com/updates/${process.platform}/${process.arch}`, } : { type: UpdateSourceType.ElectronPublicUpdateService, repo: 'acme/desktop-app', }; updateElectronApp({ updateSource: source }); ``` -------------------------------- ### Basic Usage with update.electronjs.org Source: https://github.com/electron/update-electron-app/blob/main/README.md Drop this code into your main process to enable auto-updates using the default repository URL from your package.json. ```javascript const { updateElectronApp } = require('update-electron-app') updateElectronApp() ``` -------------------------------- ### updateElectronApp(options?) — Initialize auto-updates Source: https://context7.com/electron/update-electron-app/llms.txt The primary entry point for initializing auto-updates. Call this once in your Electron main process to set up the autoUpdater feed URL, register event listeners, and schedule update checks. It handles development mode and unsupported platforms silently. Accepts an optional `IUpdateElectronAppOptions` object for configuration. ```APIDOC ## `updateElectronApp(options?)` — Initialize auto-updates ### Description The primary entry point. Call it once in your Electron main process. It validates options, sets up the `autoUpdater` feed URL, registers event listeners, and schedules periodic update checks. It silently exits in development mode (`app.isPackaged === false`) and on unsupported platforms. Accepts an optional `IUpdateElectronAppOptions` object. ### Usage Examples #### Minimal setup using update.electronjs.org (repo auto-detected from package.json) ```js const { updateElectronApp } = require('update-electron-app'); updateElectronApp(); ``` #### With explicit options using the public update service ```js const { updateElectronApp, UpdateSourceType } = require('update-electron-app'); updateElectronApp({ updateSource: { type: UpdateSourceType.ElectronPublicUpdateService, repo: 'my-org/my-app', // format: "owner/repo" host: 'https://update.electronjs.org', // optional, this is the default }, updateInterval: '30 minutes', // minimum: '5 minutes' logger: require('electron-log'), // any object with a .log() method notifyUser: true, // show restart dialog after download }); ``` #### With static file storage (S3, GCS, etc.) ```js updateElectronApp({ updateSource: { type: UpdateSourceType.StaticStorage, baseUrl: `https://my-bucket.s3.amazonaws.com/releases/${process.platform}/${process.arch}`, // macOS: appends /RELEASES.json automatically and uses serverType 'json' // Windows: uses the baseUrl directly }, updateInterval: '1 hour', notifyUser: true, }); // Expected static file layout on your storage provider: // s3://my-bucket/releases/win32/x64/RELEASES // s3://my-bucket/releases/darwin/arm64/RELEASES.json // s3://my-bucket/releases/darwin/arm64/MyApp-1.2.0.zip ``` ``` -------------------------------- ### Usage with Static File Storage Source: https://github.com/electron/update-electron-app/blob/main/README.md Configure the module to use static file storage for updates, providing a base URL for your update files. ```javascript const { updateElectronApp, UpdateSourceType } = require('update-electron-app') updateElectronApp({ updateSource: { type: UpdateSourceType.StaticStorage, baseUrl: `https://my-bucket.s3.amazonaws.com/my-app-updates/${process.platform}/${process.arch}` } }) ``` -------------------------------- ### makeUserNotifier Source: https://context7.com/electron/update-electron-app/llms.txt Creates a pre-built `(info: IUpdateInfo) => void` callback for `onNotifyUser`. This helper displays a customizable Electron `dialog.showMessageBox` to prompt the user for a restart. When the user confirms the restart, it automatically calls `autoUpdater.quitAndInstall()`. ```APIDOC ## `makeUserNotifier(dialogProps?)` — Create a custom restart-prompt callback A helper that returns a pre-built `(info: IUpdateInfo) => void` callback suitable for use as the `onNotifyUser` option. It shows an Electron `dialog.showMessageBox` with configurable title, detail text, and button labels. When the user clicks the restart button (index 0), it calls `autoUpdater.quitAndInstall()`. ### Parameters #### `dialogProps` (object) - Optional Configuration options for the dialog box. - **title** (string) - The title of the dialog. - **detail** (string) - The main text content of the dialog. Can include `{version}` placeholder. - **restartButtonText** (string) - Text for the restart button. - **laterButtonText** (string) - Text for the 'remind me later' button. ### Example Usage ```js const { updateElectronApp, makeUserNotifier } = require('update-electron-app'); const notifier = makeUserNotifier({ title: 'Update Ready', detail: 'Version {version} has been downloaded and is ready to install.', restartButtonText: 'Restart Now', laterButtonText: 'Remind Me Later', }); updateElectronApp({ // ... other options onNotifyUser: notifier, }); ``` ### `onNotifyUser` Callback Signature ```typescript (info: IUpdateInfo) => void ``` Where `IUpdateInfo` is: ```typescript interface IUpdateInfo { event: Electron.Event; releaseNotes: string; releaseName: string; // e.g. "v1.4.2" releaseDate: Date; updateURL: string; } ``` ``` -------------------------------- ### Custom Usage with update.electronjs.org Source: https://github.com/electron/update-electron-app/blob/main/README.md Configure custom options for update.electronjs.org, including specifying the repository, update interval, and a custom logger. ```javascript const { updateElectronApp, UpdateSourceType } = require('update-electron-app') updateElectronApp({ updateSource: { type: UpdateSourceType.ElectronPublicUpdateService, repo: 'github-user/repo' }, updateInterval: '1 hour', logger: require('electron-log') }) ``` -------------------------------- ### Configure Auto-Updates with Static File Storage Source: https://context7.com/electron/update-electron-app/llms.txt Configure updates using a base URL for static file storage providers like AWS S3 or Google Cloud Storage. Ensure the correct file layout on your storage. ```javascript // ─── With static file storage (S3, GCS, etc.) ──────────────────────────────── updateElectronApp({ updateSource: { type: UpdateSourceType.StaticStorage, baseUrl: `https://my-bucket.s3.amazonaws.com/releases/${process.platform}/${process.arch}`, // macOS: appends /RELEASES.json automatically and uses serverType 'json' // Windows: uses the baseUrl directly }, updateInterval: '1 hour', notifyUser: true, }); // Expected static file layout on your storage provider: // s3://my-bucket/releases/win32/x64/RELEASES // s3://my-bucket/releases/darwin/arm64/RELEASES.json // s3://my-bucket/releases/darwin/arm64/MyApp-1.2.0.zip ``` -------------------------------- ### Create a Custom Restart Prompt with makeUserNotifier Source: https://context7.com/electron/update-electron-app/llms.txt Use makeUserNotifier to create a pre-built callback for the onNotifyUser option. This helper allows customization of dialog titles, details, and button labels for restart prompts. When the user chooses to restart, it automatically calls autoUpdater.quitAndInstall(). ```javascript const { updateElectronApp, makeUserNotifier, UpdateSourceType } = require('update-electron-app'); // Build a notifier with custom strings const notifier = makeUserNotifier({ title: 'Update Ready', detail: 'Version {version} has been downloaded and is ready to install.', restartButtonText: 'Restart Now', laterButtonText: 'Remind Me Later', }); updateElectronApp({ updateSource: { type: UpdateSourceType.ElectronPublicUpdateService, repo: 'acme/desktop-app', }, notifyUser: true, onNotifyUser: notifier, // onNotifyUser receives an IUpdateInfo object: // { // event: Electron.Event, // releaseNotes: string, // releaseName: string, // e.g. "v1.4.2" // releaseDate: Date, // updateURL: string, // } }); ``` -------------------------------- ### Configure Auto-Updates with Explicit Options Source: https://context7.com/electron/update-electron-app/llms.txt Set explicit options for the update source, interval, logger, and user notifications. Supports the public update service. ```javascript // ─── With explicit options using the public update service ─────────────────── const { updateElectronApp, UpdateSourceType } = require('update-electron-app'); updateElectronApp({ updateSource: { type: UpdateSourceType.ElectronPublicUpdateService, repo: 'my-org/my-app', // format: "owner/repo" host: 'https://update.electronjs.org', // optional, this is the default }, updateInterval: '30 minutes', // minimum: '5 minutes' logger: require('electron-log'), // any object with a .log() method notifyUser: true, // show restart dialog after download }); ``` -------------------------------- ### updateElectronApp Source: https://context7.com/electron/update-electron-app/llms.txt The main function to initialize the auto-update process in your Electron application. It takes an options object to configure the update source, interval, logging, and user notification behavior. ```APIDOC ## `updateElectronApp(options)` — Initialize auto-update Initializes the auto-update process for your Electron application. This function should typically be called once in your main process entry point. ### Parameters #### `options` (IUpdateElectronAppOptions) - Required An object containing configuration for the update process. ### `IUpdateElectronAppOptions` Interface All fields are optional. The `repo` and `host` top-level fields are deprecated in favour of the `updateSource` object. - **updateSource** (object) - Specifies the source of updates. - **type** (UpdateSourceType) - The type of update source (e.g., `UpdateSourceType.ElectronPublicUpdateService`, `UpdateSourceType.StaticStorage`). - **repo** (string) - Required for `UpdateSourceType.ElectronPublicUpdateService`. Format: "owner/repo". - **host** (string) - Deprecated. Use `baseUrl` within `updateSource` for custom hosts. - **baseUrl** (string) - For `UpdateSourceType.StaticStorage`, the base URL of your storage bucket. - **updateInterval** (string) - How often to check for updates (e.g., '20 minutes'). Must be >= 5 minutes and < 2^31 ms. - **logger** (ILogger) - A custom logger object compatible with the `ILogger` interface (e.g., `electron-log`). - **log** (function) - Logs a message. - **info** (function) - Logs an informational message. - **warn** (function) - Logs a warning. - **error** (function) - Logs an error. - **notifyUser** (boolean) - If true, a notification will be shown to the user when an update is ready. Defaults to true. - **onNotifyUser** (function) - A callback function to override the default user notification logic. Receives an `IUpdateInfo` object. ### Example Usage ```js const { updateElectronApp, UpdateSourceType } = require('update-electron-app'); const options = { updateSource: { type: UpdateSourceType.ElectronPublicUpdateService, repo: 'acme/desktop-app', }, updateInterval: '1 hour', // logger: myCustomLogger, // Optional custom logger notifyUser: true, // onNotifyUser: customNotificationHandler, // Optional custom notification handler }; updateElectronApp(options); ``` ### Validation Rules - `updateInterval` must be >= 5 minutes and < 2^31 ms. - `host` / `baseUrl` must be a valid HTTPS URL. - `repo` must be in "owner/repo" format. - In development (`app.isPackaged === false`), the call is a no-op. - On Linux, the call is a no-op (autoUpdater not supported). ``` -------------------------------- ### Implement Fully Custom User Notification Logic Source: https://context7.com/electron/update-electron-app/llms.txt Bypass the default makeUserNotifier dialog by providing a custom onNotifyUser callback. This allows for in-app notifications, such as sending a message to the renderer process to display a custom UI for update readiness. ```javascript updateElectronApp({ updateSource: { type: UpdateSourceType.ElectronPublicUpdateService, repo: 'acme/desktop-app' }, notifyUser: true, onNotifyUser: ({ releaseName, releaseNotes }) => { // Send an in-app notification via your renderer process instead of a dialog const { BrowserWindow } = require('electron'); BrowserWindow.getAllWindows()[0]?.webContents.send('update-ready', { version: releaseName, notes: releaseNotes, }); }, }); ``` -------------------------------- ### UpdateSourceType — Enum for selecting the update source Source: https://context7.com/electron/update-electron-app/llms.txt An enum used to specify the update source. It has two values: `ElectronPublicUpdateService` for the `update.electronjs.org` server (requires a public GitHub repository) and `StaticStorage` for user-supplied base URLs pointing to self-hosted build artifacts. ```APIDOC ### `UpdateSourceType` — Enum for selecting the update source ### Description An enum with two values that determines how the module constructs the `autoUpdater` feed URL. `ElectronPublicUpdateService` targets the update.electronjs.org server and requires a public GitHub repository with published releases. `StaticStorage` targets a user-supplied base URL pointing to self-hosted build artifacts. ### Values - `UpdateSourceType.ElectronPublicUpdateService` - `UpdateSourceType.StaticStorage` ### Usage Example ```ts import { UpdateSourceType } from 'update-electron-app'; // UpdateSourceType.ElectronPublicUpdateService → 0 // UpdateSourceType.StaticStorage → 1 // Use in a conditional to switch sources by environment: const source = process.env.UPDATE_SOURCE === 'static' ? { type: UpdateSourceType.StaticStorage, baseUrl: `https://cdn.example.com/updates/${process.platform}/${process.arch}`, } : { type: UpdateSourceType.ElectronPublicUpdateService, repo: 'acme/desktop-app', }; updateElectronApp({ updateSource: source }); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.