ガイド
Electron Updater についてのチュートリアル
@capgo/electron-updater を使用すると、Electron アプリケーションに capgo ライブアップデートモデルを与えます。
@capgo/electron-updater gives Electron apps the same Capgo live-update model as @capgo/capacitor-updater __CAPGO_KEEP_0__ 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();
レンダラー使用
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_KEEP_0__チャネルとロールアウトモデルを再利用してください。既存のモバイルアプリケーションと同じバックエンドリリースパイプラインを共有するElectronアプリケーションでは既に使用しているものを。
- Reuse the same Capgo channel and rollout model you already use on mobile when your Electron app shares a backend release pipeline.
Using @capgo/electron-updater
Capgoを使用している場合 Using @capgo/electron-updater ネイティブプラグインの作業を計画する場合、@__CAPGO_KEEP_0__/electron-updaterと接続してください。 @capgo/electron-updater @capgo/electron-updaterの実装詳細については Electron UpdaterのGetting Started Electron UpdaterのGetting Startedの実装詳細については Capgo プラグインディレクトリ Capgo プラグインディレクトリの製品ワークフローについて Capacitor Plugins by Capgo Capacitor プラグインのCapgo プラグインの追加または更新 プラグインの追加または更新の実装詳細のため