npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

graceful-updater

v34.0.2

Published

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

Downloads

7

Readme

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 });
});

文档

参数

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

UpdateInfo

| 字段 | 类型 | 是否必须 | 说明 | 默认值 | | --- | --- | --- | --- | --- | | version | String | 必须 | 版本号 | | | projectVersion | Number | 非必须 | 构建号 | | | files | Array<Object> | 必须 | 需要下载的文件列表,返回数据遵循 File 对象 | | | updateType | Enum<String> | 必须 | 更新类型,全量更新或者动态更新。Package 为全量更新,Asar 为动态更新 | | | releaseNotes | Array<String> | 必须 | 更新日志 | |

File

| 字段 | 类型 | 是否必须 | 说明 | 默认值 | | --- | --- | --- | --- | --- | | url | String | 必须 | 下载地址 | | | signature | String | 非必须 | 下载签名 | | | updateType | Enum<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

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

贡献者

|xudafeng|zlyi|snapre|yinrouni| | :---: | :---: | :---: | :---: |

git-contributor 说明,自动生成时间:Wed May 21 2025 20:05:27 GMT+0800

License

The MIT License (MIT)