Skip to main content
플러그인으로 돌아가기
@capgo/electron-updater
튜토리얼
@capgo/electron-updater

전자 업데이터

OTA live updates for Electron apps with the same API surface as capacitor-updater

__CAPGO_KEEP_0__에서 Electron 앱에 대해 알아보기

Electron 앱에 __CAPGO_KEEP_0__ 라이브 업데이트 모델을 제공합니다.

Using @capgo/electron-updater

@capgo/electron-updater gives Electron apps the same Capgo live-update model as @capgo/capacitor-updater__CAPGO_KEEP_0__ notifyAppReady() __CAPGO_KEEP_0__

__CAPGO_KEEP_0__

bun add @capgo/electron-updater

Main process setup

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 usage

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 보호가 작동하도록 하기 위해
  • 빌드된 내장 경로를 안정적으로 유지하고 업데이터가 shipped bundle 또는 다운로드 한 bundle 중 하나를 로드할지 결정하도록 하세요.
  • 모바일에서 이미 사용 중인 Capgo 채널과 롤아웃 모델을 재사용하세요. Electron 앱이 백엔드 릴리스 PIPELINE을 공유할 때

Using @capgo/electron-updater에서 계속 진행하세요

Electron 앱을 사용 중이고 Electron Updater를 사용하여 @capgo 자연 플러그인 작업을 계획하고 @__CAPGO_KEEP_0__ @capgo/electron-updater 자연 플러그인 작업을 계획하고 @capgo Electron Updater의 implementation detail Electron Updater의 implementation detail Capgo Plugin Directory for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, and Electron Updater 플러그인 추가 또는 업데이트 Electron Updater 플러그인 추가 또는 업데이트