Zum Inhalt springen

Electron Updater API Reference

Dieser Inhalt ist in Ihrer Sprache noch nicht verfügbar.

This page documents all available methods, events, and configuration options for the Electron Updater.

Must be called on every app launch. Confirms the bundle loaded successfully and prevents automatic rollback.

await updater.notifyAppReady();

Download a bundle from a URL.

const bundle = await updater.download({
url: 'https://example.com/bundle.zip',
version: '1.0.1',
checksum: 'sha256-hash', // Optional but recommended
sessionKey: '...', // For encrypted bundles
});

Parameters:

OptionTypeRequiredDescription
urlstringYesURL to download the bundle from
versionstringYesVersion identifier for the bundle
checksumstringNoSHA256 checksum for verification
sessionKeystringNoSession key for encrypted bundles

Returns: BundleInfo object with id, version, status

Queue a bundle to be loaded on next app restart.

await updater.next({ id: 'bundle-id' });

Parameters:

OptionTypeRequiredDescription
idstringYesBundle ID to queue

Immediately switch to a bundle and reload the app.

await updater.set({ id: 'bundle-id' });

Parameters:

OptionTypeRequiredDescription
idstringYesBundle ID to activate

Manually reload the app with the current bundle.

await updater.reload();

Delete a bundle from storage.

await updater.delete({ id: 'bundle-id' });

Parameters:

OptionTypeRequiredDescription
idstringYesBundle ID to delete

Reset to builtin version or last successful bundle.

// Reset to builtin
await updater.reset({ toLastSuccessful: false });
// Reset to last successful bundle
await updater.reset({ toLastSuccessful: true });

Parameters:

OptionTypeRequiredDescription
toLastSuccessfulbooleanNoIf true, reset to last successful bundle instead of builtin

Get information about the current bundle and native version.

const info = await updater.current();
// { bundle: { id, version, status }, native: '1.0.0' }

List all downloaded bundles.

const bundles = await updater.list();
// [{ id, version, status, downloaded, checksum }, ...]

Get the bundle queued for next restart.

const next = await updater.getNextBundle();
// { id, version, status } or null

Get information about the last failed update (useful for debugging rollbacks).

const failed = await updater.getFailedUpdate();
// { id, version, reason } or null

Get the version shipped with the app binary.

const version = await updater.getBuiltinVersion();
// '1.0.0'

Check the server for the latest available version.

const latest = await updater.getLatest();
if (latest.url && !latest.error) {
// Update available
console.log('New version:', latest.version);
console.log('Download URL:', latest.url);
} else if (latest.error) {
console.error('Error checking updates:', latest.error);
}

Returns:

PropertyTypeDescription
urlstringDownload URL (empty if no update)
versionstringAvailable version
checksumstringSHA256 checksum
sessionKeystringEncryption session key
errorstringError message if check failed
messagestringServer message

Assign the device to a specific channel.

await updater.setChannel({ channel: 'beta' });

Remove channel assignment and use default.

await updater.unsetChannel();

Get the current channel assignment.

const channel = await updater.getChannel();
// { channel: 'production', status: 'set' }

List all available channels for this app.

const channels = await updater.listChannels();
// ['production', 'beta', 'staging']

Control when downloaded updates are applied.

Set conditions that must be met before an update is applied.

// Wait for app to be backgrounded
await updater.setMultiDelay({
delayConditions: [{ kind: 'background' }]
});
// Wait until specific date
await updater.setMultiDelay({
delayConditions: [{ kind: 'date', value: '2024-12-25T00:00:00Z' }]
});
// Wait for app to be killed and restarted
await updater.setMultiDelay({
delayConditions: [{ kind: 'kill' }]
});
// Multiple conditions (all must be met)
await updater.setMultiDelay({
delayConditions: [
{ kind: 'background' },
{ kind: 'date', value: '2024-12-25T00:00:00Z' }
]
});

Delay Condition Types:

KindValueDescription
backgroundOptional duration (ms)Wait for app to be backgrounded
kill-Wait for app to be killed and restarted
dateISO date stringWait until specific date/time
nativeVersionVersion stringWait for native app update

Clear all delay conditions and apply update immediately on next check.

await updater.cancelDelay();

Get the unique device identifier.

const deviceId = await updater.getDeviceId();
// 'uuid-xxxx-xxxx-xxxx'

Set a custom identifier for the device (useful for analytics).

await updater.setCustomId({ customId: 'user-123' });

Change the update server URL at runtime.

await updater.setUpdateUrl({ url: 'https://my-server.com/updates' });

Change the statistics reporting URL.

await updater.setStatsUrl({ url: 'https://my-server.com/stats' });

Change the channel management URL.

await updater.setChannelUrl({ url: 'https://my-server.com/channel' });

Change the App ID at runtime.

await updater.setAppId({ appId: 'com.example.newapp' });

Get the current App ID.

const appId = await updater.getAppId();

Enable or disable the debug menu.

await updater.setDebugMenu({ enabled: true });

Check if the debug menu is enabled.

const enabled = await updater.isDebugMenuEnabled();

Listen to update events using addListener:

updater.addListener('eventName', (event) => {
// Handle event
});
EventPayloadDescription
download{ percent, status }Download progress updates
updateAvailable{ bundle }New update available
noNeedUpdate{ message }Already up-to-date
downloadComplete{ bundle }Download finished successfully
downloadFailed{ bundle, error }Download failed
breakingAvailable{ bundle }Incompatible update available (requires native update)
updateFailed{ bundle, reason }Update installation failed
appReloaded{}App was reloaded
appReady{}notifyAppReady() was called
// Progress tracking
updater.addListener('download', (event) => {
updateProgressBar(event.percent);
});
// Update available notification
updater.addListener('updateAvailable', (event) => {
showNotification(`Update ${event.bundle.version} available!`);
});
// Handle completion
updater.addListener('downloadComplete', async (event) => {
// Queue for next restart
await updater.next({ id: event.bundle.id });
showNotification('Update will apply on next restart');
});
// Handle failures
updater.addListener('updateFailed', (event) => {
console.error('Update failed:', event.reason);
reportError(event);
});

Full configuration options for ElectronUpdater:

const updater = new ElectronUpdater({
// Required
appId: 'com.example.app',
// Version override
version: '1.0.0', // Override builtin version detection
// Server URLs
updateUrl: 'https://plugin.capgo.app/updates',
channelUrl: 'https://plugin.capgo.app/channel_self',
statsUrl: 'https://plugin.capgo.app/stats',
// Behavior
autoUpdate: true, // Enable automatic update checks
appReadyTimeout: 10000, // Milliseconds before rollback (default: 10000)
autoDeleteFailed: true, // Auto-delete failed bundles
autoDeletePrevious: true, // Auto-delete old bundles
resetWhenUpdate: true, // Reset to builtin on native update
// Channels
defaultChannel: 'production',
// Direct Update Mode
directUpdate: false, // 'atInstall' | 'onLaunch' | 'always' | false
// Security
publicKey: '...', // RSA public key for E2E encryption
// Dynamic Configuration
allowModifyUrl: false, // Allow runtime URL changes
allowModifyAppId: false, // Allow runtime App ID changes
persistCustomId: false, // Persist custom ID across updates
persistModifyUrl: false, // Persist URL changes
// Debug
debugMenu: false, // Enable debug menu (Ctrl+Shift+D)
disableJSLogging: false, // Disable console logs
// Periodic Updates
periodCheckDelay: 0, // Seconds between auto-checks (0 = disabled, min 600)
});