Electron Updater API リファレンス
このプラグインのインストール手順とフルマークダウンガイドのセットアッププロンプトをコピーする
Electron Updaterの利用可能なすべてのメソッド、イベント、および設定オプションをドキュメント化しています。
Core Methods
「Core Methods」notifyAppReady()
「notifyAppReady()」アプリ起動毎に呼び出す必要があります。 bundleの正常なロードを確認し、自動ロールバックを防止します。
await updater.notifyAppReady();download(options)
セクション「download(options)」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 | string | Yes | URL to download the bundle from |
version | string | Yes | Version identifier for the bundle |
checksum | string | No | SHA256 checksum for verification |
sessionKey | string | No | Session key for encrypted bundles |
戻り値: BundleInfo オブジェクト id, version, status
次のオプション
「次のオプション」セクションアプリ再起動時にバンドルをロードするように予約します。
await updater.next({ id: 'bundle-id' });引数:
| オプション | 型 | 必要 | 説明 |
|---|---|---|---|
id | 文字列 | Yes | Bundle IDをキューに追加 |
set(options)
「set(options)」というセクションアプリを即座にバンドルに切り替え、リロードします。
await updater.set({ id: 'bundle-id' });引数:
| オプション | 型 | 必要 | 説明 |
|---|---|---|---|
id | 文字列 | Yes | Bundle ID to activate |
reload()
Section titled “reload()”Manually reload the app with the current bundle.
await updater.reload();delete(options)
Section titled “delete(options)”Delete a bundle from storage.
await updater.delete({ id: 'bundle-id' });Parameters:
| Option | タイプ | 必要 | 説明 |
|---|---|---|---|
id | 文字列 | はい | 削除するBundle ID |
reset(options)
セクションのタイトル “reset(options)”バンドルバージョンまたは最後の成功バンドルにリセットします。
// Reset to builtinawait updater.reset({ toLastSuccessful: false });
// Reset to last successful bundleawait updater.reset({ toLastSuccessful: true });パラメータ:
| オプション | 種類 | 必要 | 説明 |
|---|---|---|---|
toLastSuccessful | boolean | No | trueの場合、ビルトインの代わりに最後の成功バンドルにリセットします。 |
バンドル情報
「バンドル情報」というセクションcurrent()
「current()」というセクション現在のバンドルとネイティブバージョンの情報を取得します。
const info = await updater.current();// { bundle: { id, version, status }, native: '1.0.0' }list(options)
セクション「list(options)」ダウンロードしたすべてのバンドルをリストアップします。
const bundles = await updater.list();// [{ id, version, status, downloaded, checksum }, ...]getNextBundle()
セクション「getNextBundle()」次の再起動で実行されるバンドルの情報を取得します。
const next = await updater.getNextBundle();// { id, version, status } or nullgetFailedUpdate()
セクション「getFailedUpdate()」最後の更新でエラーが発生した際の詳細情報を取得します。(ロールバックのデバッグに役立ちます)。
const failed = await updater.getFailedUpdate();// { id, version, reason } or nullgetBuiltinVersion()
getBuiltinVersion()のセクションアプリバイナリに組み込まれたバージョンを取得します。
const version = await updater.getBuiltinVersion();// '1.0.0'更新チェック
更新チェックのセクションgetLatest(options)
getLatest(options)のセクションサーバーから最新のバージョンをチェックします。
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 | __CAPGO_KEEP_0__ | __CAPGO_KEEP_0__ |
version | __CAPGO_KEEP_0__ | 利用可能なバージョン |
checksum | __CAPGO_KEEP_0__ | SHA256チェックサム |
sessionKey | __CAPGO_KEEP_0__ | 暗号化セッションキー |
error | __CAPGO_KEEP_0__ | エラー メッセージ (チェック失敗時) |
message | string | サーバーからのメッセージ |
チャンネル管理
チャンネル管理setChannel(options)
setChannel(options)デバイスを特定のチャンネルに割り当てる。
await updater.setChannel({ channel: 'beta' });unsetChannel(options)
setChannel(options)チャンネル割り当てを解除し、デフォルトを使用。
await updater.unsetChannel();getChannel()
セクション「getChannel()」現在のチャネル割り当てを取得します。
const channel = await updater.getChannel();// { channel: 'production', status: 'set' }listChannels()
セクション「listChannels()」このアプリの利用可能なチャネルの一覧を表示します。
const channels = await updater.listChannels();// ['production', 'beta', 'staging']延期条件
セクション「延期条件」ダウンロードした更新を適用するタイミングを制御します。
setMultiDelay(options)
「setMultiDelay(options)」セクション更新が適用される前に満たす必要のある条件を設定します。
// Wait for app to be backgroundedawait updater.setMultiDelay({ delayConditions: [{ kind: 'background' }]});
// Wait until specific dateawait updater.setMultiDelay({ delayConditions: [{ kind: 'date', value: '2024-12-25T00:00:00Z' }]});
// Wait for app to be killed and restartedawait 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 | - | アプリが終了して再起動されるのを待つ |
date | ISO 日付文字列 | 特定の日時まで待つ |
nativeVersion | バージョン文字列 | ネイティブアプリの更新を待つ |
cancelDelay()
「cancelDelay()」すべての遅延条件をクリアし、次のチェックで即座に更新を適用する。
await updater.cancelDelay();デバイス識別
「デバイス識別」getDeviceId()
「getDeviceId()」一意のデバイス識別子を取得する。
const deviceId = await updater.getDeviceId();// 'uuid-xxxx-xxxx-xxxx'setCustomId(options)
セクション「setCustomId(options)」デバイスにカスタム識別子を設定します (分析用)。
await updater.setCustomId({ customId: 'user-123' });setUpdateUrl(options)
セクション「setUpdateUrl(options)」更新サーバー URL を実行時で変更します。
await updater.setUpdateUrl({ url: 'https://my-server.com/updates' });setStatsUrl(options)
Section titled “setStatsUrl(options)”Change the statistics reporting URL.
await updater.setStatsUrl({ url: 'https://my-server.com/stats' });setChannelUrl(options)
Section titled “setChannelUrl(options)”Change the channel management URL.
await updater.setChannelUrl({ url: 'https://my-server.com/channel' });setAppId(options)
Section titled “setAppId(options)”実行時でApp IDを変更します。
await updater.setAppId({ appId: 'com.example.newapp' });getAppId()
「getAppId()」のセクション現在のApp IDを取得します。
const appId = await updater.getAppId();デバッグ
「デバッグ」のセクションsetDebugMenu(options)
「setDebugMenu(options)」セクションデバッグメニューの有効化/無効化
await updater.setDebugMenu({ enabled: true });isDebugMenuEnabled()
「isDebugMenuEnabled()」セクションデバッグメニューが有効かどうかを確認
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 | {} | App が再読み込みされました |
appReady | {} | notifyAppReady() __CAPGO_KEEP_0__ が呼び出されました |
例: フル イベント ハンドリング
「例: フル イベント ハンドリング」のセクション// Progress trackingupdater.addListener('download', (event) => { updateProgressBar(event.percent);});
// Update available notificationupdater.addListener('updateAvailable', (event) => { showNotification(`Update ${event.bundle.version} available!`);});
// Handle completionupdater.addListener('downloadComplete', async (event) => { // Queue for next restart await updater.next({ id: event.bundle.id }); showNotification('Update will apply on next restart');});
// Handle failuresupdater.addListener('updateFailed', (event) => { console.error('Update failed:', event.reason); reportError(event);});コンストラクタ オプション
「コンストラクタ オプション」のセクションElectron Updater から続けて __CAPGO_KEEP_0__ リファレンス 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 リファレンスから続けてください」のセクションCapgo を使用している場合 Electron Updater API Reference ダッシュボードとAPIの計画と運用のために接続する Using @capgo/electron-updater Capacitorのネイティブ機能のためにUsing @capgo/electron-updater API Overview Capacitorの実装詳細のためにAPI Overview Introduction 実装詳細のためにIntroduction API Keys 実装詳細のためにAPI Keys Devices 実装詳細のためにDevices