안내서
Electron 업데이터 튜토리얼
Using @capgo/electron-updater
@capgo/electron-updater Electron 앱에 Capgo live-update 모델을 제공합니다. @capgo/capacitor-updatermain process에서 초기화하고, preload를 통해 렌더러 브리지를 노출하고, notifyAppReady() launch마다 호출하여 rollback 보호가 bundle의 건강을 알 수 있도록 합니다.
설치
bun add @capgo/electron-updater
main process 설정
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());
});
preload 브리지를 설정
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에서 rollback 보호가 작동하도록 하기 위해 rollback을 하기 전에 호출한다. - 빌드-in 경로를 안정적으로 유지하고 업데이트기가 shipped 번들을 로드하거나 다운로드 한 번들을 로드할지 결정하도록 한다.
- 기존의 모바일에서 이미 사용중인 Capgo 채널과 롤아웃 모델을 재사용하라. Electron 앱이 백엔드 릴리즈 PIPELINE을 공유할 때
Using @capgo/electron-updater를 사용하는 경우
Using @__CAPGO_KEEP_0__/electron-updater를 사용하여 Using @capgo/electron-updater If you are using @capgo/electron-updater @capgo/electron-updater Electron Updater를 사용하기 위한 시작 Electron Updater를 사용하기 위한 시작 Capgo 플러그인 디렉토리 Capgo 플러그인 디렉토리 Capacitor 플러그인들 - Capgo Capacitor 플러그인들 - Capgo 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트