가이드
Electron에서 Electron Updater 사용 방법
@capgo/electron-updater 사용하기
@capgo/electron-updater Electron 앱에 Capgo와 동일한 Live Update 모델을 제공합니다. @capgo/capacitor-updater메인 프로세스에서 초기화하고, preload를 통해 renderer bridge를 노출한 뒤 호출하세요. notifyAppReady() 번들이 정상인지 rollback protection이 확인할 수 있도록 실행 시마다 수행합니다.
설치
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 bridge
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()rollback protection이 의도대로 작동하도록 renderer 초기 단계에서 실행합니다. - 내장된 경로는 고정하고, 업데이트 도구가 배포된 번들을 로드할지 다운로드된 번들을 로드할지 결정하게 합니다.
- Electron 앱이 백엔드 릴리스 파이프라인을 공유한다면, 모바일에서 사용 중인 Capgo 채널과 롤아웃 모델을 그대로 재사용하세요.
@capgo/electron-updater 사용하기 단계부터 계속 진행하세요
사용 중이라면 @capgo/electron-updater 사용하기 네이티브 플러그인 작업을 계획하려면, 이를 다음 항목과 연결하세요: @capgo/electron-updater @capgo/electron-updater의 구현 세부 사항은 Electron Updater 시작하기 Electron Updater 시작하기에서의 구현 세부 사항은 Capgo 플러그인 디렉토리 Capgo Plugin Directory의 제품 워크플로우에 맞춰, Capgo의 Capacitor 플러그인 Capgo의 Capacitor Plugins 구현 세부 사항 및 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트의 구현 세부 사항은.