Electron Updater API 参考
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
__CAPGO_KEEP_3__
__CAPGO_KEEP_4__
__CAPGO_KEEP_5____CAPGO_KEEP_6__
__CAPGO_KEEP_7____CAPGO_KEEP_8__ __CAPGO_KEEP_9__
await updater.notifyAppReady();download(options)
下载选项从 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});参数:
| 选项 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
url | string | 只 | 下载包的 URL |
version | string | 只 | 李架标凹代码 |
checksum | string | 不 | 因队强为码配缀的配缀 |
sessionKey | string | 不 | 当前的管球服务号 |
返回: BundleInfo 对象 id, version, status
next(options)
标题:“next(options)”在下一次应用重启时将包队列加载。
await updater.next({ id: 'bundle-id' });参数:
| 选项 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | 字符串 | 是 | Bundle ID到队列 |
__CAPGO_KEEP_0__
标题:__CAPGO_KEEP_0__立即切换到一个捆绑包并重新加载应用。
await updater.set({ id: 'bundle-id' });参数:
| 选项 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | 字符串 | 是 | 激活包ID |
reload()
重新加载(reload())手动重新加载当前包
await updater.reload();delete(options)
删除选项(delete(options))从存储中删除包
await updater.delete({ id: 'bundle-id' });参数:
| 选项 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | 字符串 | 是 | 要删除的包ID |
reset(options)
标题:“reset(options)”重置为内置版本或最后一次成功的包。
// Reset to builtinawait updater.reset({ toLastSuccessful: false });
// Reset to last successful bundleawait updater.reset({ toLastSuccessful: true });参数:
| 选项 | 类型 | 必填 | 描述 |
|---|---|---|---|
toLastSuccessful | boolean | 否 | 如果为真,则重置为最后一次成功的捆绑包而不是内置捆绑包 |
捆绑包信息
标题:捆绑包信息current()
标题:current()获取当前捆绑包和本机版本的信息
const info = await updater.current();// { bundle: { id, version, status }, native: '1.0.0' }list(options)
列表(options)列出所有下载的包。
const bundles = await updater.list();// [{ id, version, status, downloaded, checksum }, ...]getNextBundle()
下一次重启时排队的包复制到剪贴板
const next = await updater.getNextBundle();// { id, version, status } or null获取最后一次失败的更新信息(用于调试回滚)
复制到剪贴板getFailedUpdate()
const failed = await updater.getFailedUpdate();// { id, version, reason } or null获取内置版本()
标题:获取内置版本()获取与应用程序二进制文件一起发布的版本。
const version = await updater.getBuiltinVersion();// '1.0.0'更新检查
标题:更新检查获取最新版本(options)
标题:获取最新版本(options)检查服务器以获取最新可用版本。
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);}返回:
| 属性 | 类型 | 描述 |
|---|---|---|
url | 字符串 | 下载 URL (如果没有更新则为空) |
version | 字符串 | 可用版本 |
checksum | SHA256 校验和 | 字符串 |
sessionKey | 加密会话密钥 | 字符串 |
error | 检查失败时的错误消息 | __CAPGO_KEEP_0__ |
message | string | 服务器消息 |
频道管理
频道管理设置频道(options)
设置频道(options)将设备分配到特定的频道。
await updater.setChannel({ channel: 'beta' });取消频道(options)
设置频道(options)移除频道分配并使用默认值。
await updater.unsetChannel();获取当前频道分配。
频道获取(getChannel())获取当前频道分配。
const channel = await updater.getChannel();// { channel: 'production', status: 'set' }获取所有可用频道(listChannels())
频道列表(listChannels())列出此应用程序的所有可用频道。
const channels = await updater.listChannels();// ['production', 'beta', 'staging']控制下载的更新何时应用。
设置多延迟(setMultiDelay(options))
setMultiDelay(options)设置更新应用之前必须满足的条件。
// 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' } ]});延迟条件类型:
| 类型 | 值 | 描述 |
|---|---|---|
background | 可选持续时间(毫秒) | 等待应用进入后台 |
kill | - | 等待应用被杀死并重启 |
date | ISO 日期字符串 | 等待特定日期/时间 |
nativeVersion | 版本字符串 | 等待原生应用更新 |
cancelDelay()
取消延迟(cancelDelay())清除所有延迟条件并在下一次检查时立即应用更新。
await updater.cancelDelay();getDeviceId()
设备唯一标识符(getDeviceId())获取设备的唯一标识符。
const deviceId = await updater.getDeviceId();// 'uuid-xxxx-xxxx-xxxx'setCustomId(options)
Section titled “setCustomId(options)”为设备设置一个自定义标识符(用于分析)。
await updater.setCustomId({ customId: 'user-123' });setUpdateUrl(options)
Section titled “setUpdateUrl(options)”在运行时更改更新服务器 URL。
await updater.setUpdateUrl({ url: 'https://my-server.com/updates' });设置统计URL(options)
标题:设置统计URL(options)修改统计报告URL
await updater.setStatsUrl({ url: 'https://my-server.com/stats' });设置渠道URL(options)
标题:设置渠道URL(options)修改渠道管理URL
await updater.setChannelUrl({ url: 'https://my-server.com/channel' });设置应用ID(options)
标题:设置应用ID(options)在运行时更改 App ID。
await updater.setAppId({ appId: 'com.example.newapp' });getAppId()
标题:getAppId()获取当前 App ID。
const appId = await updater.getAppId();调试
标题:调试设置调试菜单(options)
标题:设置调试菜单(options)启用或禁用调试菜单。
await updater.setDebugMenu({ enabled: true });isDebugMenuEnabled()
标题:isDebugMenuEnabled()检查是否启用了调试菜单。
const enabled = await updater.isDebugMenuEnabled();事件
标题:事件使用 addListener:
updater.addListener('eventName', (event) => { // Handle event});可用事件
可用事件| 事件 | 事件数据 | 描述 |
|---|---|---|
download | { percent, status } | 下载进度更新 |
updateAvailable | { bundle } | 新版本可用 |
noNeedUpdate | { message } | 已是最新 |
downloadComplete | { bundle } | 下载成功 |
downloadFailed | { bundle, error } | 下载失败 |
breakingAvailable | { bundle } | 不兼容的更新 (需要原生更新) |
updateFailed | { bundle, reason } | 更新安装失败 |
appReloaded | {} | App 已经重新加载 |
appReady | {} | notifyAppReady() __CAPGO_KEEP_0__被调用 |
示例:全事件处理
标题:示例:全事件处理// 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);});构造函数选项
标题:构造函数选项全配置选项 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)});从 Electron Updater 继续 API 参考
标题:从 Electron Updater 继续 API 参考如果您正在使用 Electron Updater API Reference 为了计划仪表板和API操作,连接它 使用@capgo/electron-updater 使用@capgo/electron-updater的本机功能 API Overview 查看API Overview中的实现细节 介绍 查看介绍中的实现细节 API Keys 查看API Keys中的实现细节 设备 查看设备中的实现细节