Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graceful-updater

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graceful-updater

graceful-updater is a software updator management solution for Electron applications, It is convenient to complete full software update and dynamic update.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

graceful-updater

NPM version CI node version npm download

Electron 应用软件更新解决方案,方便完成软件的全量更新和动态更新。

English | 简体中文

Installment

$ npm i graceful-updater --save

样例

点击查看: https://github.com/electron-modules/electron-modules-sample

// 1. 构造 options
const options = {
  url: getFeedUrl(),
  logger: console, // logger
  productName: 'demo',
  updateInfoFormatter: (res) => {
    return res;
  },
  ifNeedUpdate: (res) => {
    console.log('local version', currentVersion);
    console.log('local project version', currentBuildNumber);
    console.log('remote version', res.version);
    console.log('remote project version', res.project_version);
    return semver.gt(res.version, currentVersion) ||
      res.project_version > currentBuildNumber;
  },
};
// 2. 初始化 updator 实例
const electronUpdator = new MacUpdator(options);
// 3. 绑定全局事件
electronUpdator.on(EventType.UPDATE_DOWNLOADED, (...args) => {
  console.log('updator >> %s, args: %j', EventType.UPDATE_DOWNLOADED, args);
});
electronUpdator.on(EventType.CHECKING_FOR_UPDATE, (...args) => {
  console.log('updator >> %s, args: %j', EventType.CHECKING_FOR_UPDATE, args);
});
electronUpdator.on(EventType.UPDATE_AVAILABLE, (data) => {
  const { version, project_version } = data?.updateInfo || {};
  const message = [
    'available',
    `local version: ${currentVersion}`,
    `local project version: ${currentBuildNumber}`,
    `remote version: ${version}`,
    `remote project version: ${project_version}`,
  ].join('\n');
  dialog.showMessageBoxSync({
    message,
  });
});
electronUpdator.on(EventType.UPDATE_NOT_AVAILABLE, (data) => {
  const { version, project_version } = data?.updateInfo || {};
  const message = [
    'not available',
    `local version: ${currentVersion}`,
    `local project version: ${currentBuildNumber}`,
    `remote version: ${version}`,
    `remote project version: ${project_version}`,
  ].join('\n');
  dialog.showMessageBoxSync({
    message,
  });
});
electronUpdator.on(EventType.ERROR, (...args) => {
  console.log('updator >> %s, args: %j', EventType.ERROR, args);
});
electronUpdator.on(EventType.UPDATE_DOWNLOAD_PROGRESS, (data) => {
  const { status, progress } = data;
  console.log('updator >> %s, status: %s, progress: %d', EventType.UPDATE_DOWNLOAD_PROGRESS, status, progress);
  app.windowManager.get('updator').webContents.send('updator:updateDownloadProgress', { status, progress });
});

文档

参数

字段类型是否必须说明默认值
urlString必须检测更新的远程地址,返回数据遵循 UpdateInfo 对象
ifNeedUpdateFunction必须返回是否需要更新
updateInfoFormatterFunction非必须服务端返回数据格式适配。如果返回的格式无法与 UpdateInfo 相匹配时,可通过此方法进行格式化
loggerObject非必须日志console
productNameString必须应用完整名称
autoDownloadString非必须是否自动下载false
getWindowsHelperExeDirFunction非必须Windows 下 helper 目录false

UpdateInfo

字段类型是否必须说明默认值
versionString必须版本号
projectVersionNumber非必须构建号
filesArray<Object>必须需要下载的文件列表,返回数据遵循 File 对象
updateTypeEnum<String>必须更新类型,全量更新或者动态更新。Package 为全量更新,Asar 为动态更新
releaseNotesArray<String>必须更新日志

File

字段类型是否必须说明默认值
urlString必须下载地址
signatureString非必须下载签名
updateTypeEnum<String>必须更新类型,针对动态更新或全量更新提供的下载地址。Package or Asar

方法

  1. checkForUpdates(ExecuteType)
  • ExecuteType 执行类型(User or Auto)

检测是否有需要更新的内容,如果 ExecuteType 为 User,则检查到更新后直接触发 update-available 事件,否则将自动下载完成安装包后触发 update-available 事件

  1. setFeedUrl(url)
  • url 新的更新 URL 根据不同场景需要,动态设置检查更新的 URL
  1. downloadUpdate(ExecuteType)
  • ExecuteType 执行类型(User or Auto)

开始下载安装包,如果 ExecuteType 为 User,则不进行预检查,下载完成后直接触发 update-downloaded 事件,否则完成内部完成预检查后再触发 update-downloaded 事件

  1. quitAndInstall() 退出应用并开始安装。如果安装包已下载完成,将直接重启应用并进行新版本安装。否则进入下载流程

事件

  1. checking-for-update

当开始检查更新的时候触发

  1. update-available
  • params:更新信息
  • params.updateInfo:本次更新的信息 UpdateInfo

检测到有可用更新时触发

  1. update-not-available
  • params:更新信息
  • params.updateInfo:本次更新的信息 UpdateInfo

检测到无可用更新时触发

  1. update-download-progress
  • params:下载过程中的进度及文件流信息。
  • params.status 下载状态。 begin 开始下载,downloading 下载中,end 下载结束
  • params.progress 当前下载进度百分比,0 ~ 100
  • params.data 下载内容的文件流,可利用此数据进行签名校验

正在下载过程中触发

  1. update-downloaded

完成下载时触发

  1. error
  • params:错误信息 Error

更新程序内部出现错误时触发

Contributors


zlyi


xudafeng


snapre

This project follows the git-contributor spec, auto updated at Tue Jan 31 2023 14:31:40 GMT+0800.

License

The MIT License (MIT)

Keywords

FAQs

Package last updated on 21 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc