ガイド
エレクトロン アップデートのチュートリアル
エレクトロン アップデートの@capgo/electron-updater
@capgo/electron-updater エレクトロン アプリケーションに Capgo ライブ アップデート モデルを提供します。 @capgo/capacitor-updaterエレクトロン アップデートの初期化 notifyAppReady() メイン プロセスの設定
プレロード ブリッジの設定
bun add @capgo/electron-updater
インストール
import { app, BrowserWindow } from 'electron';
import path from 'node:path';
import { ElectronUpdater, setupEventForwarding, setupIPCHandlers } from '@capgo/electron-updater';
const updater = new ElectronUpdater({
appId: 'com.example.desktop',
autoUpdate: true,
});
app.whenReady().then(async () => {
const window = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
},
});
const builtinPath = path.join(__dirname, 'www/index.html');
await updater.initialize(window, builtinPath);
setupIPCHandlers(updater);
setupEventForwarding(updater, window);
await window.loadFile(updater.getCurrentBundlePath());
});
メイン プロセスの設定はここにあります。
import { exposeUpdaterAPI } from '@capgo/electron-updater/preload';
exposeUpdaterAPI();
Rendererの使用
import { requireUpdater } from '@capgo/electron-updater/renderer';
const updater = requireUpdater();
await updater.notifyAppReady();
const latest = await updater.getLatest();
if (latest.url && !latest.error) {
const bundle = await updater.download({
url: latest.url,
version: latest.version,
checksum: latest.checksum,
});
await updater.next({ id: bundle.id });
}
更新イベントを待ち受ける
updater.addListener('download', ({ percent }) => {
console.log('Download progress', percent);
});
updater.addListener('updateFailed', ({ bundle }) => {
console.error('Update failed', bundle.version);
});
新しいバンドルを展開
bun run build
bunx @capgo/cli@latest bundle upload --channel=production
実践的なアドバイス
- 常に
notifyAppReady()Rendererで早期に呼び出すようにして、ロールバック保護が正常に機能するようにします。 - 組み込まれたパスを安定させて、アップデーターが配布されたバンドルかダウンロードしたバンドルを読み込むかを決定するようにしてください。
- Capgoチャネルとロールアウトモデルを再利用してください。既存のモバイルアプリと同じバックエンドリリースパイプラインを共有するElectronアプリの場合。
Using @capgo/electron-updaterから続けてください。
Using @__CAPGO_KEEP_0__/electron-updaterを使用している場合 native pluginの作業を計画するには、@capgo/electron-updaterを接続してください Electronアプリでバックエンドリリースパイプラインを共有している場合 @capgo/electron-updater @capgo/electron-updater Electron Updaterの導入 Electron Updaterの導入 Capgo プラグインディレクトリ Capgo プラグインディレクトリ Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, and プラグインの追加または更新 プラグインの追加または更新