メインコンテンツにジャンプ

Electron UpdaterAPIリファレンス

GitHub

このページでは、Electron Updaterの利用可能なすべてのメソッド、イベント、設定オプションをドキュメント化しています。

基本メソッド

「基本メソッド」

notifyAppReady()

notifyAppReady()

notifyAppReady()を毎回アプリ起動時に呼び出す必要があります。 bundleのロードが成功したことを確認し、自動ロールバックを防止します。

await updater.notifyAppReady();

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

パラメーター:

オプション必要説明
url文字列はいダウンロードするバンドルのURL
version文字列はいバンドルのバージョン識別子
checksum文字列いいえ暗号化されたバンドルの検証用SHA256チェックサム
sessionKey文字列いいえ暗号化されたバンドルのセッションキー

戻り値: BundleInfo オブジェクト id, version, status

次のオプションを指定して呼び出す

「次のオプション」を指定して呼び出す

再起動時にバンドルを読み込むためにキューする。

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

パラメータ:

オプションタイプ必要説明
id文字列はい再起動時に読み込むバンドルID

即時でアプリを再読み込みします。

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

パラメータ:

オプションタイプ必須説明
id文字列はいアクティブ化するバンドルID

現在のバンドルでアプリを手動で再読み込みします。

await updater.reload();

クリップボードにコピー

delete(options)のセクション

ストレージからバンドルを削除します。

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

パラメータ:

オプション必須説明
id文字列はい削除するBundle ID

バンドル版または最後の成功バンドルに戻します。

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

パラメーター:

オプションタイプ必要説明
toLastSuccessfulbooleanなしtrueの場合、ビルトインの代わりに最後の成功バンドルにリセットします

バンドル情報

バンドル情報

コピー

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

バンドルをリストする

コピー

バンドルをリストする

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

getNextBundle()

getNextBundle()

次の再起動で実行されるバンドルの取得

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

getFailedUpdate()

getFailedUpdate()

最後の更新でエラーが発生したときの情報を取得する (ロールバックのデバッグに役立ちます)

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

getBuiltinVersion()

getBuiltinVersion()

アプリバイナリに組み込まれたバージョンの取得

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

戻り値:

プロパティ説明
url文字列ダウンロードURL(更新がない場合は空)
version__CAPGO_KEEP_0__利用可能なバージョン
checksum__CAPGO_KEEP_1__SHA256チェックサム
sessionKey__CAPGO_KEEP_2__暗号化セッションキー
error__CAPGO_KEEP_3__チェック失敗時のエラーメッセージ
message__CAPGO_KEEP_4__サーバーメッセージ

チャンネル管理

チャンネル管理

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

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バージョン文字列ネイティブアプリの更新を待つ

次回のチェック時に即時更新を適用するために、すべての遅延条件をクリアします。

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 }互換性のないアップデートが利用可能 (ネイティブのアップデートが必要)
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);
});

Electron Updaterの完全な構成オプション 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の__CAPGO_KEEP_0__ Reference Electron UpdaterのAPI Reference Electron UpdaterのAPI Reference Electron Updaterのcapgo Reference Electron Updaterのcapgo Reference API Overview API の概要 Introduction __CAPGO_KEEP_0__ の概要 API Keys API キー Devices デバイス