Getting Started mit Electron Updater
Kopiere einen Setup-Prompt mit den Installationsschritten und dem vollständigen Markdown-Guide für dieses Plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/electron-updater`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/electron-updater/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Diese Anleitung führt dich durch das Setup @capgo/electron-updater in deiner Electron-App, um Live-Updates für JavaScript/HTML/CSS zu aktivieren.
Voraussetzungen
Abschnitt: „Voraussetzungen“- Electron 20.0.0 oder höher
- Node.js 18 oder höher
- Ein Capgo Account (registriere dich unter capgo.app)
Installation
Abschnitt mit dem Titel „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge die Capgo Skills mit dem folgenden Befehl deinem KI-Tool hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze dann diesen Prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/electron-updater` plugin in my project.Wenn du ein manuelles Setup bevorzugst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:
-
Installiere das Package:
Terminalfenster npm install @capgo/electron-updater -
Hol dir deine App-ID aus dem Capgo Dashboard. Falls du noch keine App erstellt hast, führe aus:
Terminalfenster npx @capgo/cli@latest init
Quickstart
Abschnitt „Quick start“import { requireUpdater } from '@capgo/electron-updater/renderer';
const updater = requireUpdater();await updater.notifyAppReady();Häufige Stolperfallen
Abschnitt „Häufige Fallstricke“- Rufe
notifyAppReady()frühzeitig beim Start – innerhalb des konfigurierten Timeouts – vor einer langsamen UI-Initialisierung. - Stimme Capgo im Main-Prozess ab.
- Update-Channels festlegen, bevor der Release erfolgt.
Setup
Abschnitt „Setup“Der Electron Updater muss an drei Stellen konfiguriert werden: im Main Process, im Preload Script und im Renderer Process.
Main-Prozess
Abschnitt „Main Process“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 IDconst 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-Skript
Abschnitt „Preload Script“import { exposeUpdaterAPI } from '@capgo/electron-updater/preload';
// Expose the updater API to the renderer processexposeUpdaterAPI();Renderer-Prozess
Abschnitt mit dem Titel „Renderer Process“// 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 rollbackawait updater.notifyAppReady();
console.log('App ready, current bundle:', await updater.current());Updates prüfen
Abschnitt mit dem Titel „Checking for Updates“Mit autoUpdate: true, prüft der Updater automatisch auf Updates. Du kannst auch manuelle Checks auslösen:
// Check for updates manuallyconst 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 });}Events abhören
Abschnitt mit dem Titel „Listening to Events“Verfolge den Update-Fortschritt und Status mit Events:
// Download progressupdater.addListener('download', (event) => { console.log(`Download progress: ${event.percent}%`);});
// Update availableupdater.addListener('updateAvailable', (event) => { console.log('New version available:', event.bundle.version);});
// Download completedupdater.addListener('downloadComplete', (event) => { console.log('Download finished:', event.bundle.id);});
// Update failedupdater.addListener('updateFailed', (event) => { console.error('Update failed:', event.bundle.version);});Updates deployen
Abschnitt mit dem Titel „Deploying Updates“Nutze Capgo CLI, um Updates hochzuladen:
# Build your appnpm run build
# Upload to Capgonpx @capgo/cli@latest bundle upload --channel=productionDeine Electron-App erkennt und lädt das neue Bundle beim nächsten Check automatisch herunter.
Debug-Menü
Abschnitt „Debug Menu“Aktivieren Sie das Debug Menu während der Entwicklung:
const updater = new ElectronUpdater({ appId: 'YOUR_CAPGO_APP_ID', debugMenu: true, // Enable debug menu});Drücken Ctrl+Shift+D (oder Cmd+Shift+D auf dem Mac) um das Debug Menu zu öffnen und:
- Aktuelle Bundle-Infos anzeigen
- Zwischen verfügbaren Bundles wechseln
- Auf Builtin-Version zurücksetzen
- Geräte- und Channel-Infos anzeigen
Konfigurationsoptionen
Abschnitt mit dem Titel „Konfigurationsoptionen“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)});Nächste Schritte
Abschnitt „Nächste Schritte“- API Referenz - Entdecke alle verfügbaren Methoden
- Channels - Erfahre mehr über Deployment-Channels
- Rollbacks - Verstehe den Rollback-Schutz
Weiterlesen nach dem Getting Started mit Electron Updater
Abschnitt mit dem Titel „Weiterlesen nach dem Getting Started mit Electron Updater“Wenn du es nutzt Erste Schritte mit Electron Updater Um die Arbeit an nativen Plugins zu planen, verbinde sie mit @capgo/electron-updater verwenden für die native Funktionalität bei „@capgo/electron-updater verwenden“, Capgo Plugin-Verzeichnis für den Produkt-Workflow im Capgo Plugin-Verzeichnis, Capacitor Plugins von Capgo für das Implementierungsdetail in Capacitor Plugins von Capgo, Plugins hinzufügen oder aktualisieren für das Implementierungsdetail beim Hinzufügen oder Aktualisieren von Plugins, und Ionic Enterprise Plugin-Alternativen für den Produkt-Workflow bei den Ionic Enterprise Plugin-Alternativen.