メインコンテンツへスキップ

Electron Updater API リファレンス

GitHub

このページでは、Electron Updater で利用可能なすべてのメソッド、イベント、および設定オプションについて説明します。

アプリの起動ごとに呼び出す必要があります。 bundle が正常にロードされたことを確認し、自動ロールバックを防ぎます。

await updater.notifyAppReady();

URLからbundleをダウンロードします。

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
});

パラメータ:

オプション種類必須説明
urlstringはいbundleのダウンロード先URL
versionstringはいbundleのバージョン識別子
checksumstringいいえ検証用のSHA256チェックサム
sessionKeystringいいえ暗号化されたbundle用のセッションキー

戻り値: BundleInfo 以下のプロパティを持つオブジェクト: id, version, status

次回のアプリ再起動時にロードするbundleをキューに追加します。

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

パラメータ:

オプション種類必須説明
idstringはいキューに入れるBundle ID

即座にbundleを切り替え、アプリをリロードします。

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

パラメータ:

オプション種類必須説明
idstringはい有効化するBundle ID

現在のbundleを使用してアプリを手動でリロードします。

await updater.reload();

ストレージからbundleを削除します。

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

パラメータ:

オプション種類必須説明
idstringはい削除するBundle ID

組み込みバージョンまたは最後に成功したbundleにリセットします。

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

パラメータ:

オプション種類必須説明
toLastSuccessfulbooleanいいえtrueの場合、内蔵の代わりに最後に成功したbundleにリセットします

現在のbundleとnativeバージョンの情報を取得します。

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

ダウンロード済みのすべてのbundleをリストアップします。

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

次回の再起動時に適用される予定のbundleを取得します。

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

最後に失敗したアップデートの情報を取得します(ロールバックのデバッグに便利です)。

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

アプリのバイナリに同梱されているバージョンを取得します。

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

サーバー上の最新バージョンを確認します。

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);
}

戻り値:

プロパティ種類説明
urlstringダウンロードURL(アップデートがない場合は空)
versionstring利用可能なバージョン
checksumstringSHA256チェックサム
sessionKeystring暗号化セッションキー
errorstringチェックに失敗した場合のエラーメッセージ
messagestringサーバーメッセージ

デバイスを特定のチャンネルに割り当てます。

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

チャンネルの割り当てを解除し、デフォルトを使用します。

await updater.unsetChannel();

現在割り当てられているチャンネルを取得します。

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

このアプリで利用可能なすべてのチャンネルをリストアップします。

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

ダウンロードされたアップデートの適用タイミングを制御します。

アップデートを適用する前に満たすべき条件を設定します。

// 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' }
]
});

遅延条件のタイプ:

種類値説明
backgroundオプションの待ち時間 (ms)アプリがバックグラウンドになるまで待機
kill-アプリが終了し、再起動されるまで待機
dateISO形式の日付文字列指定した日時まで待機
nativeVersionバージョン文字列Native Buildのアップデートを待機

すべての遅延条件をクリアし、次回のチェック時に即座にアップデートを適用します。

await updater.cancelDelay();

デバイス固有の識別子を取得します。

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

デバイスにカスタム識別子を設定します(分析に便利です)。

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

実行時にアップデートサーバーのURLを変更します。

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

統計レポートのURLを変更します。

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

チャンネル管理のURLを変更します。

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

実行時にApp IDを変更します。

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

現在のApp IDを取得します。

const appId = await updater.getAppId();

デバッグメニューの有効/無効を切り替えます。

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

デバッグメニューが有効かどうかを確認します。

const enabled = await updater.isDebugMenuEnabled();

以下の方法でアップデートイベントをリッスンします: addListener:

updater.addListener('eventName', (event) => {
// Handle event
});
イベントペイロード説明
download{ percent, status }ダウンロードの進捗状況
updateAvailable{ bundle }新しいアップデートが利用可能
noNeedUpdate{ message }既に最新の状態です
downloadComplete{ bundle }ダウンロードが正常に完了しました
downloadFailed{ bundle, error }ダウンロードに失敗しました
breakingAvailable{ bundle }互換性のないアップデートがあります(Native Buildが必要です)
updateFailed{ bundle, reason }アップデートのインストールに失敗しました
appReloaded{}アプリがリロードされました
appReady{}notifyAppReady() が呼び出されました

例:イベントハンドリングの完全な実装

「例:イベントハンドリングの完全な実装」セクション
// 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);
});

の完全な設定オプション 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)
});

Electron Updater API リファレンスへ戻る

「Electron Updater API リファレンス」セクション

以下を使用している場合: Electron Updater API リファレンス ダッシュボードと API の操作を計画するには、以下と連携してください @capgo/electron-updater の使用方法 @capgo/electron-updater を使用したネイティブ機能について、 API の概要 API Overview の実装の詳細については、 はじめに Introduction の実装の詳細については、 API キー API Keys の実装の詳細については、 デバイス Devices の実装の詳細については。