Electron Updaterの始め方
このプラグインのインストールステップとフルマークダウンガイドのセットアッププロンプトをコピーする。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/electron-updater`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/electron-updater/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
このガイドでは、ElectronアプリケーションにLive JavaScript/HTML/CSS更新を有効にするために設定方法を説明します。 @capgo/electron-updater Tip
Electron 20.0.0 またはそれ以上
Node.js 18 またはそれ以上- __CAPGO_KEEP_0__アカウント (
- __CAPGO_KEEP_0__.appで登録
- Capgo capgo.app)
インストール
インストールAI-Assisted セットアップを使用してプラグインをインストールできます。次のコマンドを使用して、AI ツールに Capgo スキルを追加します。
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins次のプロンプトを使用してください。
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/electron-updater` plugin in my project.Manual セットアップを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。
-
パッケージをインストールします。
ターミナル bun add @capgo/electron-updater -
App ID を Capgo ダッシュボードから取得します。アプリを作成していない場合は、以下のコマンドを実行してください。
ターミナル画面 npx @capgo/cli@latest init
セットアップ
セットアップElectron Updaterには、main process、preload script、renderer processの3つの場所でセットアップが必要です。
メインプロセス
メインプロセスimport { app, BrowserWindow } from 'electron';import * as path from 'path';import { ElectronUpdater, setupIPCHandlers, setupEventForwarding,} from '@capgo/electron-updater';
// Create updater instance with your Capgo App IDconst updater = new ElectronUpdater({ appId: 'YOUR_CAPGO_APP_ID', // e.g., 'com.example.myapp' autoUpdate: true,});
app.whenReady().then(async () => { const mainWindow = new BrowserWindow({ width: 1200, height: 800, webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, }, });
// Initialize updater with window and builtin path const builtinPath = path.join(__dirname, 'www/index.html'); await updater.initialize(mainWindow, builtinPath);
// Setup IPC communication between main and renderer setupIPCHandlers(updater); setupEventForwarding(updater, mainWindow);
// Load the current bundle (either builtin or downloaded update) await mainWindow.loadFile(updater.getCurrentBundlePath());});
app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); }});プリロードスクリプト
プリロードスクリプトimport { exposeUpdaterAPI } from '@capgo/electron-updater/preload';
// Expose the updater API to the renderer processexposeUpdaterAPI();レンダラー プロセス
「レンダラー プロセス」のセクション// renderer.ts (or in your app's entry point)import { requireUpdater } from '@capgo/electron-updater/renderer';
const updater = requireUpdater();
// CRITICAL: Call this on every app launch!// This confirms the bundle loaded successfully and prevents rollbackawait updater.notifyAppReady();
console.log('App ready, current bundle:', await updater.current());Checking for Updates
アップデートの確認With autoUpdate: trueアップデートの確認を自動で行います。手動で確認することもできます。
// Check for updates manuallyconst latest = await updater.getLatest();
if (latest.url && !latest.error) { console.log('Update available:', latest.version);
// Download the update const bundle = await updater.download({ url: latest.url, version: latest.version, checksum: latest.checksum, });
console.log('Downloaded bundle:', bundle.id);
// Option 1: Queue for next restart await updater.next({ id: bundle.id });
// Option 2: Apply immediately and reload // await updater.set({ id: bundle.id });}イベントのリスニング
Section titled “Listening to Events”イベントを通じてアップデートの進行状況とステータスを追跡できます。
// Download progressupdater.addListener('download', (event) => { console.log(`Download progress: ${event.percent}%`);});
// Update availableupdater.addListener('updateAvailable', (event) => { console.log('New version available:', event.bundle.version);});
// Download completedupdater.addListener('downloadComplete', (event) => { console.log('Download finished:', event.bundle.id);});
// Update failedupdater.addListener('updateFailed', (event) => { console.error('Update failed:', event.bundle.version);});アップデートのデプロイ
Section titled “Deploying Updates”Capgo CLI を使用してアップデートをアップロードします。
# Build your appnpm run build
# Upload to Capgonpx @capgo/cli@latest bundle upload --channel=productionあなたの Electron アプリは、次のチェック時に自動的に新しいバンドルを検出してダウンロードします。
デバッグ メニュー
「デバッグ メニュー」というセクション開発中はデバッグ メニューを有効にします:
const updater = new ElectronUpdater({ appId: 'YOUR_CAPGO_APP_ID', debugMenu: true, // Enable debug menu});「コマンド + Shift + I」(または「コマンド + オプション + I」) Ctrl+Shift+D Mac の場合) を押してデバッグ メニューを開き、以下の操作を行います: Cmd+Shift+D 現在のバンドル情報を表示
- 利用可能なバンドル間で切り替え
- バイトインバウンドバンドルに戻す
- __CAPGO_KEEP_0__
- デバイスとチャンネル情報を表示
設定オプション
「設定オプション」セクションconst updater = new ElectronUpdater({ // Required appId: 'com.example.app',
// Server URLs (defaults to Capgo Cloud) updateUrl: 'https://plugin.capgo.app/updates', channelUrl: 'https://plugin.capgo.app/channel_self', statsUrl: 'https://plugin.capgo.app/stats',
// Behavior autoUpdate: true, // Enable auto-updates appReadyTimeout: 10000, // MS before rollback (default: 10s) autoDeleteFailed: true, // Delete failed bundles autoDeletePrevious: true, // Delete old bundles after successful update
// Channels defaultChannel: 'production',
// Security publicKey: '...', // For end-to-end encryption
// Debug debugMenu: false, // Enable debug menu disableJSLogging: false, // Disable console logs
// Periodic Updates periodCheckDelay: 0, // Seconds between checks (0 = disabled, min 600)});次のステップ
「次のステップ」セクション- API リファレンス - 使用可能なすべてのメソッドを探索
- チャンネル - デプロイチャンネルについて学ぶ
- ロールバック - ロールバック保護について理解する
Electron Updaterから始めて続ける
Electron Updaterから始めて続けるElectron Updaterを使用している場合 Electron Updaterから始めて続ける Electron Updaterを使用して、ネイティブ プラグインの作業計画に接続する Electron Updater (@capgo/electron-updater)を使用して、Electron Updaterのネイティブ機能と接続する capgo プラグイン ディレクトリ Capgo プラグイン ディレクトリ Capgo プラグイン (@__CAPGO_KEEP_1__) Capacitor プラグイン (@Capgo) for the implementation detail in Capacitor Plugins by Capgo, Electron Updaterから始めて続ける 実装詳細の追加または更新の場合の実装詳細の詳細については、 Ionic Enterprise Plugin Alternatives Ionic Enterprise Plugin Alternativesの製品ワークフローについては、