Electron Updater API リファレンス
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
このページでは、Electron Updater で利用可能なすべてのメソッド、イベント、および設定オプションを説明します。
コアメソッド
セクション「コアメソッド」notifyAppReady()
「notifyAppReady()」セクションアプリの起動時に毎回呼び出す必要があります。 バンドルの正常な読み込みを確認し、自動ロールバックを防止します。
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 | 文字列 | はい | バンドルをダウンロードするURL |
version | 文字列 | はい | バンドルのバージョン識別子 |
checksum | 文字列 | いいえ | 検証用のSHA256チェックサム |
sessionKey | 文字列 | いいえ | 暗号化されたバンドル用のセッションキー |
戻り値: BundleInfo オブジェクト id, version, status
next(options)
セクション「next(options)」次のアプリ再起動時に読み込まれるようバンドルをキューに追加します。
await updater.next({ id: 'bundle-id' });パラメーター:
| オプション | 種類 | 必須 | 説明 |
|---|---|---|---|
id | 文字列 | はい | キューに入れるBundle ID |
set(options)
「set(options)」セクション即座にbundleを切り替え、アプリをリロードします。
await updater.set({ id: 'bundle-id' });パラメーター:
| オプション | 種類 | 必須 | 説明 |
|---|---|---|---|
id | 文字列 | はい | 有効にするBundle ID |
reload()
「reload()」セクション現在のBundleでアプリを手動でリロードします。
await updater.reload();delete(options)
セクション「delete(options)」ストレージからBundleを削除します。
await updater.delete({ id: 'bundle-id' });パラメーター:
| オプション | 種類 | 必須 | 説明 |
|---|---|---|---|
id | 文字列 | はい | 削除するBundle ID |
reset(options)
「reset(options)」セクション組み込みバージョンまたは最後に成功したbundleにリセットします。
// Reset to builtinawait updater.reset({ toLastSuccessful: false });
// Reset to last successful bundleawait updater.reset({ toLastSuccessful: true });パラメーター:
| オプション | 種類 | 必須 | 説明 |
|---|---|---|---|
toLastSuccessful | boolean | いいえ | trueの場合、組み込みの代わりに最後に成功したbundleにリセットします |
Bundle 情報
「Bundle 情報」というタイトルのセクション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'更新チェック
「Update Checking」セクション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 | 文字列 | ダウンロード URL(更新がない場合は空) |
version | 文字列 | 利用可能なバージョン |
checksum | 文字列 | SHA256 チェックサム |
sessionKey | 文字列 | 暗号化セッションキー |
error | 文字列 | チェック失敗時のエラーメッセージ |
message | 文字列 | サーバーメッセージ |
setChannel(options)
「setChannel(options)」セクションデバイスを特定のチャンネルに割り当てます。
await updater.setChannel({ channel: 'beta' });unsetChannel(options)
セクション「unsetChannel(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' } ]});ディレイ条件の種類:
| Kind | 値 | 説明 |
|---|---|---|
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)
「setStatsUrl(options)」セクション統計レポートのURLを変更します。
await updater.setStatsUrl({ url: 'https://my-server.com/stats' });setChannelUrl(options)
「setChannelUrl(options)」セクションチャネル管理のURLを変更します。
await updater.setChannelUrl({ url: 'https://my-server.com/channel' });setAppId(options)
セクション「setAppId(options)」実行時にApp IDを変更します。
await updater.setAppId({ appId: 'com.example.newapp' });getAppId()
セクション「getAppId()」現在のApp IDを取得します。
const appId = await updater.getAppId();デバッグ
「Debug」セクションsetDebugMenu(options)
「setDebugMenu(options)」セクションデバッグメニューの有効/無効を切り替えます。
await updater.setDebugMenu({ enabled: true });isDebugMenuEnabled()
「isDebugMenuEnabled()」セクションデバッグメニューが有効かどうかを確認します。
const enabled = await updater.isDebugMenuEnabled();イベント
「Events」セクションで更新イベントをリッスンします 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 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);});コンストラクタオプション
セクション「コンストラクタオプション」の完全な設定オプション 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 の使い方 Using @capgo/electron-updater でのネイティブ機能については、 API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー および「API Keys」の実装の詳細については、 デバイス 実装の詳細については Devices を参照してください。