메인 콘텐츠로 건너뛰기
플러그인으로 돌아가기
@capgo/electron-updater
튜토리얼
github.com/Cap-go에서 github

이레크론 업데이터

API Surface와 capacitor-업데이터와 동일한 이레크론 앱의 OTA 실시간 업데이트

안내서

Electron 업데이터 튜토리얼

@capgo/electron-updater를 사용하여

@capgo/electron-updater Electron 앱에 Capgo 라이브 업데이트 모델을 제공합니다. @capgo/capacitor-updatermain process에서 초기화하고, preload를 통해 렌더러 브리지를 노출하고, notifyAppReady() launch마다 호출하여 롤백 보호가 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();

렌더러 사용

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

실용적인 조언

  • 항상 렌더러에서 rollback 보호 기능이 작동하도록 하기 위해 __CAPGO_KEEP_0__을 호출하세요. notifyAppReady() 빌드된 경로를 안정적으로 유지하고 업데이터가 shipped 번들을 다운로드한 번들을 로드할지 결정하도록 하세요.
  • __CAPGO_KEEP_0__ 채널과 롤아웃 모델을 재사용하세요. 이 모델은 이미 모바일에서 사용 중인 것과 동일해야 합니다. Electron 앱이 백엔드 릴리스 PIPELINE을 공유할 때.
  • Reuse the same Capgo channel and rollout model you already use on mobile when your Electron app shares a backend release pipeline.