ガイド
Electron アップデートのチュートリアル
@capgo/electron-updater を使用すると、Electron アプリに同様の capgo ライブアップデートモデルが提供されます。
@capgo/electron-updater Capgo ライブアップデートモデルと同様の機能を提供します。 @capgo/capacitor-updater初期化はメインプロセスで行います。レンダラー ブリッジをプレロードで露出させ、起動ごとに呼び出して、ロールバック保護がバンドルが正常であることを知ることができます。 notifyAppReady() インストール
__CAPGO_KEEP_0__
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();
レンダラーの使用
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()早期にレンダラーで呼び出すようにして、ロールバック保護が正常に機能するようにします。 - 組み込まれたパスを安定させて、アップデータがシップされたバンドルかダウンロードしたバンドルを読み込むかを決定するようにしてください。
- Capgoチャネルとロールアウトモデルを再利用してください。既存のモバイルアプリと同じバックエンドリリースパイプラインを共有するElectronアプリの場合。
Using @capgo/electron-updaterから続けてください。
既に Capgoの@capgo/electron-updater Capgoの@__CAPGO_KEEP_0__/electron-updaterを使用して Capgoの@capgo/electron-updater Capgoの@capgo/electron-updaterの実装詳細 Electron Updaterの使用開始 Electron Updaterの実装詳細 Capgo プラグインディレクトリ Capgo プラグインディレクトリの製品ワークフロー Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, and プラグインの追加または更新 プラグインの追加または更新の実装詳細