ガイド
Electron アップデーターに関するチュートリアル
Electron アプリケーションに同様の capgo ライブアップデートモデルを提供する @capgo/electron-updater を使用すると
@capgo/electron-updater gives Electron apps the same Capgo live-update model as @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();
レンダラーの使用
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()組み込まれたパスを安定させて、アップデートャーが実行ファイルをダウンロードしたものか、配布されたものかを判断するようにする。 - Electronアプリケーションがバックエンドリリースパイプラインを共有する場合、既存のモバイルアプリケーションで使用している同じ__CAPGO_KEEP_0__チャンネルとロールアウトモデルを再利用すること。
- Capgo
Using @capgo/electron-updater
あなたが使用している場合 Using @capgo/electron-updater ネイティブ プラグインの作業を計画する場合、@__CAPGO_KEEP_0__/electron-updaterと接続してください。 @capgo/electron-updaterと接続してください。 Electron Updaterの実装詳細については、@capgo/electron-updaterを参照してください。 Electron Updaterの実装詳細については、Getting Started with Electron Updaterを参照してください。 __CAPGO_KEEP_0__ プラグイン ディレクトリ Capgo プラグイン ディレクトリの製品ワークフローについては、Capgo Plugin Directoryを参照してください。 Capgo プラグイン Capacitor プラグインの実装詳細については、Capacitor Plugins by Capgoを参照してください。 Capacitor プラグインの実装詳細については、Capacitor Plugins by Capgoを参照してください。 プラグインの追加または更新 プラグインの追加または更新の実装詳細のために。