메뉴로 이동

Electron Updater로 시작하기

이 가이드는 Electron 애플리케이션에서 JavaScript/HTML/CSS 업데이트를 활성화하기 위해 설정하는 방법을 안내합니다. @capgo/electron-updater

  • Electron 20.0.0 이상
  • Node.js 18 이상
  • A Capgo account (sign up at capgo.app)
  1. 패키지를 설치하세요:

    터미널 창
    bun add @capgo/electron-updater
  2. Get your App ID from the Capgo dashboard. If you haven’t created an app yet, run:

    터미널 창
    npx @capgo/cli@latest init

Electron Updater는 메인 프로세스, 프리로드 스크립트, 렌더러 프로세스 세 곳에서 설정이 필요합니다.

메인 프로세스

메인 프로세스 섹션
main.ts
import { app, BrowserWindow } from 'electron';
import * as path from 'path';
import {
ElectronUpdater,
setupIPCHandlers,
setupEventForwarding,
} from '@capgo/electron-updater';
// Create updater instance with your Capgo App ID
const updater = new ElectronUpdater({
appId: 'YOUR_CAPGO_APP_ID', // e.g., 'com.example.myapp'
autoUpdate: true,
});
app.whenReady().then(async () => {
const mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
},
});
// Initialize updater with window and builtin path
const builtinPath = path.join(__dirname, 'www/index.html');
await updater.initialize(mainWindow, builtinPath);
// Setup IPC communication between main and renderer
setupIPCHandlers(updater);
setupEventForwarding(updater, mainWindow);
// Load the current bundle (either builtin or downloaded update)
await mainWindow.loadFile(updater.getCurrentBundlePath());
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});

프리로드 스크립트

프리로드 스크립트 섹션
preload.ts
import { exposeUpdaterAPI } from '@capgo/electron-updater/preload';
// Expose the updater API to the renderer process
exposeUpdaterAPI();

렌더러 프로세스

렌더러 프로세스 제목
// renderer.ts (or in your app's entry point)
import { requireUpdater } from '@capgo/electron-updater/renderer';
const updater = requireUpdater();
// CRITICAL: Call this on every app launch!
// This confirms the bundle loaded successfully and prevents rollback
await updater.notifyAppReady();
console.log('App ready, current bundle:', await updater.current());

업데이트 확인 중

업데이트 확인

업데이트를 자동으로 확인합니다. 또한 수동 확인을 트리거할 수 있습니다. autoUpdate: true복사

// Check for updates manually
const latest = await updater.getLatest();
if (latest.url && !latest.error) {
console.log('Update available:', latest.version);
// Download the update
const bundle = await updater.download({
url: latest.url,
version: latest.version,
checksum: latest.checksum,
});
console.log('Downloaded bundle:', bundle.id);
// Option 1: Queue for next restart
await updater.next({ id: bundle.id });
// Option 2: Apply immediately and reload
// await updater.set({ id: bundle.id });
}

이벤트를 통해 업데이트의 진행 상황과 상태를 추적할 수 있습니다.

복사

업데이트 배포

// Download progress
updater.addListener('download', (event) => {
console.log(`Download progress: ${event.percent}%`);
});
// Update available
updater.addListener('updateAvailable', (event) => {
console.log('New version available:', event.bundle.version);
});
// Download completed
updater.addListener('downloadComplete', (event) => {
console.log('Download finished:', event.bundle.id);
});
// Update failed
updater.addListener('updateFailed', (event) => {
console.error('Update failed:', event.bundle.version);
});

터미널 창

업데이트 확인

Use the Capgo CLI to upload updates:

복사
# Build your app
npm run build
# Upload to Capgo
npx @capgo/cli@latest bundle upload --channel=production

다음에 체크할 때 새로운 번들을 자동으로 감지하고 다운로드합니다.

debug 메뉴

debug 메뉴

개발 중에는 debug 메뉴를 활성화하세요:

const updater = new ElectronUpdater({
appId: 'YOUR_CAPGO_APP_ID',
debugMenu: true, // Enable debug menu
});

Ctrl + Shift + I (또는 Ctrl+Shift+D Mac에서 Ctrl + Option + I)로 debug 메뉴를 열고: Cmd+Shift+D 현재 번들의 정보를 확인하세요

  • 사용 가능한 번들을-switch
  • builtin 버전으로 리셋
  • Ctrl + Shift + I (또는 Mac에서 Ctrl + Option + I)
  • 장치 및 채널 정보 보기
const updater = new ElectronUpdater({
// Required
appId: 'com.example.app',
// Server URLs (defaults to Capgo Cloud)
updateUrl: 'https://plugin.capgo.app/updates',
channelUrl: 'https://plugin.capgo.app/channel_self',
statsUrl: 'https://plugin.capgo.app/stats',
// Behavior
autoUpdate: true, // Enable auto-updates
appReadyTimeout: 10000, // MS before rollback (default: 10s)
autoDeleteFailed: true, // Delete failed bundles
autoDeletePrevious: true, // Delete old bundles after successful update
// Channels
defaultChannel: 'production',
// Security
publicKey: '...', // For end-to-end encryption
// Debug
debugMenu: false, // Enable debug menu
disableJSLogging: false, // Disable console logs
// Periodic Updates
periodCheckDelay: 0, // Seconds between checks (0 = disabled, min 600)
});
  • API 참조 - 모든 사용 가능한 메서드를 탐색하십시오
  • 채널 - 배포 채널에 대해 학습하십시오
  • 롤백 - 롤백 보호에 대해 이해하십시오