Referensi Electron Updater API
Salin prompt setup yang berisi langkah install dan panduan markdown lengkap untuk plugin ini.
Halaman ini mendokumentasikan semua metode, event, dan opsi konfigurasi yang tersedia untuk Electron Updater.
Metode Inti
Bagian berjudul “Core Methods”notifyAppReady()
Bagian berjudul “notifyAppReady()”Harus dipanggil setiap kali aplikasi diluncurkan. Memastikan bundle berhasil dimuat dan mencegah rollback otomatis.
await updater.notifyAppReady();download(options)
Bagian berjudul “download(options)”Unduh bundle dari URL.
const bundle = await updater.download({ url: 'https://example.com/bundle.zip', version: '1.0.1', checksum: 'sha256-hash', // Optional but recommended sessionKey: '...', // For encrypted bundles});Parameter:
| Opsi | Tipe | Wajib | Deskripsi |
|---|---|---|---|
url | string | Ya | URL untuk mengunduh bundle |
version | string | Ya | Pengidentifikasi versi untuk bundle |
checksum | string | Tidak | Checksum SHA256 untuk verifikasi |
sessionKey | string | Tidak | Kunci sesi untuk bundle terenkripsi |
Mengembalikan: BundleInfo object dengan id, version, status
next(options)
Bagian berjudul “next(options)”Antrikan bundle untuk dimuat saat restart aplikasi berikutnya.
await updater.next({ id: 'bundle-id' });Parameter:
| Opsi | Tipe | Wajib | Deskripsi |
|---|---|---|---|
id | string | Ya | Bundle ID untuk antrean |
set(options)
Bagian berjudul “set(options)”Segera beralih ke bundle dan muat ulang aplikasi.
await updater.set({ id: 'bundle-id' });Parameter:
| Opsi | Tipe | Wajib | Deskripsi |
|---|---|---|---|
id | string | Ya | Bundle ID untuk diaktifkan |
reload()
Bagian berjudul “reload()”Muat ulang aplikasi secara manual dengan bundle saat ini.
await updater.reload();delete(options)
Bagian berjudul “delete(options)”Hapus bundle dari penyimpanan.
await updater.delete({ id: 'bundle-id' });Parameter:
| Opsi | Tipe | Wajib | Deskripsi |
|---|---|---|---|
id | string | Ya | Bundle ID yang akan dihapus |
reset(options)
Bagian berjudul “reset(options)”Reset ke versi bawaan atau bundle terakhir yang berhasil.
// Reset to builtinawait updater.reset({ toLastSuccessful: false });
// Reset to last successful bundleawait updater.reset({ toLastSuccessful: true });Parameter:
| Opsi | Tipe | Wajib | Deskripsi |
|---|---|---|---|
toLastSuccessful | boolean | Tidak | Jika true, reset ke bundle terakhir yang berhasil, bukan versi bawaan |
Informasi bundle
Bagian berjudul “Informasi Bundle”current()
Bagian berjudul “current()”Dapatkan informasi tentang bundle dan versi native saat ini.
const info = await updater.current();// { bundle: { id, version, status }, native: '1.0.0' }list(options)
Bagian berjudul “list(options)”Tampilkan semua bundle yang sudah di-download.
const bundles = await updater.list();// [{ id, version, status, downloaded, checksum }, ...]getNextBundle()
Bagian berjudul “getNextBundle()”Dapatkan bundle yang antre untuk restart berikutnya.
const next = await updater.getNextBundle();// { id, version, status } or nullgetFailedUpdate()
Bagian berjudul “getFailedUpdate()”Dapatkan informasi tentang pembaruan terakhir yang gagal (berguna untuk debugging rollback).
const failed = await updater.getFailedUpdate();// { id, version, reason } or nullgetBuiltinVersion()
Bagian berjudul “getBuiltinVersion()”Dapatkan versi yang disertakan dengan biner aplikasi.
const version = await updater.getBuiltinVersion();// '1.0.0'Pengecekan Update
Bagian berjudul “Update Checking”getLatest(options)
Bagian berjudul “getLatest(options)”Periksa server untuk versi terbaru yang tersedia.
const latest = await updater.getLatest();
if (latest.url && !latest.error) { // Update available console.log('New version:', latest.version); console.log('Download URL:', latest.url);} else if (latest.error) { console.error('Error checking updates:', latest.error);}Mengembalikan:
| Properti | Tipe | Deskripsi |
|---|---|---|
url | string | URL Download (kosong jika tidak ada update) |
version | string | Versi tersedia |
checksum | string | Checksum SHA256 |
sessionKey | string | Kunci sesi enkripsi |
error | string | Pesan error jika pemeriksaan gagal |
message | string | Pesan server |
Manajemen Channel
Bagian berjudul “Channel Management”setChannel(options)
Bagian berjudul “setChannel(options)”Tugaskan perangkat ke channel tertentu.
await updater.setChannel({ channel: 'beta' });unsetChannel(options)
Bagian berjudul “unsetChannel(options)”Hapus penetapan channel dan gunakan default.
await updater.unsetChannel();getChannel()
Bagian berjudul “getChannel()”Ambil penetapan channel saat ini.
const channel = await updater.getChannel();// { channel: 'production', status: 'set' }listChannels()
Bagian berjudul “listChannels()”Tampilkan semua channel yang tersedia untuk aplikasi ini.
const channels = await updater.listChannels();// ['production', 'beta', 'staging']Kondisi Delay
Bagian berjudul “Kondisi Penundaan”Kendalikan kapan pembaruan yang diunduh diterapkan.
setMultiDelay(options)
Bagian berjudul “setMultiDelay(options)”Atur kondisi yang harus dipenuhi sebelum pembaruan diterapkan.
// Wait for app to be backgroundedawait updater.setMultiDelay({ delayConditions: [{ kind: 'background' }]});
// Wait until specific dateawait updater.setMultiDelay({ delayConditions: [{ kind: 'date', value: '2024-12-25T00:00:00Z' }]});
// Wait for app to be killed and restartedawait updater.setMultiDelay({ delayConditions: [{ kind: 'kill' }]});
// Multiple conditions (all must be met)await updater.setMultiDelay({ delayConditions: [ { kind: 'background' }, { kind: 'date', value: '2024-12-25T00:00:00Z' } ]});Jenis Kondisi Penundaan:
| Jenis | Nilai | Deskripsi |
|---|---|---|
background | Durasi opsional (ms) | Tunggu hingga aplikasi berada di latar belakang |
kill | - | Tunggu aplikasi ditutup dan dijalankan ulang |
date | String tanggal ISO | Tunggu sampai tanggal/waktu tertentu |
nativeVersion | String versi | Tunggu update app native |
cancelDelay()
Bagian berjudul “cancelDelay()”Hapus semua kondisi delay dan langsung terapkan update pada pengecekan berikutnya.
await updater.cancelDelay();Identifikasi Perangkat
Bagian berjudul “Identifikasi Perangkat”getDeviceId()
Bagian berjudul “getDeviceId()”Dapatkan pengenal unik perangkat.
const deviceId = await updater.getDeviceId();// 'uuid-xxxx-xxxx-xxxx'setCustomId(options)
Bagian berjudul “setCustomId(options)”Atur pengenal kustom untuk perangkat (berguna untuk analitik).
await updater.setCustomId({ customId: 'user-123' });Konfigurasi
Bagian berjudul “Konfigurasi”setUpdateUrl(options)
Bagian berjudul “setUpdateUrl(options)”Ubah URL server update saat runtime.
await updater.setUpdateUrl({ url: 'https://my-server.com/updates' });setStatsUrl(options)
Bagian berjudul “setStatsUrl(options)”Ubah URL pelaporan statistik.
await updater.setStatsUrl({ url: 'https://my-server.com/stats' });setChannelUrl(options)
Bagian berjudul “setChannelUrl(options)”Ubah URL manajemen channel.
await updater.setChannelUrl({ url: 'https://my-server.com/channel' });setAppId(options)
Bagian berjudul “setAppId(options)”Ubah App ID saat runtime.
await updater.setAppId({ appId: 'com.example.newapp' });getAppId()
Bagian berjudul “getAppId()”Dapatkan App ID saat ini.
const appId = await updater.getAppId();setDebugMenu(options)
Bagian berjudul “setDebugMenu(options)”Aktifkan atau nonaktifkan menu debug.
await updater.setDebugMenu({ enabled: true });isDebugMenuEnabled()
Bagian berjudul “isDebugMenuEnabled()”Periksa apakah menu debug diaktifkan.
const enabled = await updater.isDebugMenuEnabled();Dengarkan event update menggunakan addListener:
updater.addListener('eventName', (event) => { // Handle event});Event yang Tersedia
Bagian berjudul “Event yang Tersedia”| Event | Payload | Deskripsi |
|---|---|---|
download | { percent, status } | Update progres download |
updateAvailable | { bundle } | Update baru tersedia |
noNeedUpdate | { message } | Sudah versi terbaru |
downloadComplete | { bundle } | Download berhasil diselesaikan |
downloadFailed | { bundle, error } | Download gagal |
breakingAvailable | { bundle } | Tersedia update tidak kompatibel (perlu native update) |
updateFailed | { bundle, reason } | Instalasi update gagal |
appReloaded | {} | Aplikasi telah dimuat ulang |
appReady | {} | notifyAppReady() telah dipanggil |
Contoh: Penanganan Event Lengkap
Bagian berjudul “Contoh: Penanganan Event Lengkap”// Progress trackingupdater.addListener('download', (event) => { updateProgressBar(event.percent);});
// Update available notificationupdater.addListener('updateAvailable', (event) => { showNotification(`Update ${event.bundle.version} available!`);});
// Handle completionupdater.addListener('downloadComplete', async (event) => { // Queue for next restart await updater.next({ id: event.bundle.id }); showNotification('Update will apply on next restart');});
// Handle failuresupdater.addListener('updateFailed', (event) => { console.error('Update failed:', event.reason); reportError(event);});Opsi Constructor
Bagian berjudul “Opsi Constructor”Opsi konfigurasi lengkap untuk ElectronUpdater:
const updater = new ElectronUpdater({ // Required appId: 'com.example.app',
// Version override version: '1.0.0', // Override builtin version detection
// Server URLs updateUrl: 'https://plugin.capgo.app/updates', channelUrl: 'https://plugin.capgo.app/channel_self', statsUrl: 'https://plugin.capgo.app/stats',
// Behavior autoUpdate: true, // Enable automatic update checks appReadyTimeout: 10000, // Milliseconds before rollback (default: 10000) autoDeleteFailed: true, // Auto-delete failed bundles autoDeletePrevious: true, // Auto-delete old bundles resetWhenUpdate: true, // Reset to builtin on native update
// Channels defaultChannel: 'production',
// Direct Update Mode directUpdate: false, // 'atInstall' | 'onLaunch' | 'always' | false
// Security publicKey: '...', // RSA public key for E2E encryption
// Dynamic Configuration allowModifyUrl: false, // Allow runtime URL changes allowModifyAppId: false, // Allow runtime App ID changes persistCustomId: false, // Persist custom ID across updates persistModifyUrl: false, // Persist URL changes
// Debug debugMenu: false, // Enable debug menu (Ctrl+Shift+D) disableJSLogging: false, // Disable console logs
// Periodic Updates periodCheckDelay: 0, // Seconds between auto-checks (0 = disabled, min 600)});Lanjutkan dari Electron Updater API Referensi
Bagian berjudul “Lanjutkan dari Electron Updater API Reference”Jika Anda menggunakan Referensi Electron Updater API untuk merencanakan operasi dashboard dan API, hubungkan dengan Menggunakan @capgo/electron-updater untuk kemampuan native di Menggunakan @capgo/electron-updater, Ringkasan API untuk detail implementasi di API Overview, Pendahuluan untuk detail implementasi di Introduction, Kunci API untuk detail implementasi di API Keys, dan Perangkat untuk detail implementasi di Devices.