가이드
Electron Updater를 Electron에서 사용하는 방법
@capgo/electron-updater를 사용하면
@capgo/electron-updater Electron 앱에 Capgo의 라이브 업데이트 모델을 제공합니다. @capgo/capacitor-updatermain process에서 초기화하고, preload를 통해 렌더러 브리지를 노출하고, notifyAppReady() launch마다 호출하여 롤백 보호가 bundle이 정상인지 알 수 있도록 합니다.
설치
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()렌더러에서 rollback 보호가 작동하도록 하려면 - 빌드된 경로를 안정적으로 유지하고 업데이터가 shipped 번들을 로드하거나 다운로드한 번들을 로드할지 결정하도록 하세요.
- Capgo 채널과 롤아웃 모델을 재사용하세요. 모바일에서 이미 사용 중인 것과 동일한 채널과 롤아웃 모델을 재사용하세요. Electron 앱이 백엔드 릴리스 PIPELINE을 공유할 때.
Using @capgo/electron-updater에서 계속하세요.
이러한 기능을 사용 중이라면 @capgo/electron-updater 사용 자연 플러그인 작업을 계획하기 위해 @__CAPGO_KEEP_0__/electron-updater와 연결하세요. @capgo/전자 업데이터 자연 플러그인 작업을 계획하기 위해 @capgo/electron-updater와 연결하세요. Electron Updater 시작하기 Getting Started with Electron Updater Capgo 플러그인 디렉토리 Capgo Plugin Directory Capacitor Capgo의 플러그인 Capacitor Plugins by Capgo 플러그인 추가 또는 업데이트 Capgo 플러그인 구현 세부 사항에 대한 정보입니다.