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 🙏

© 2024 – Pkg Stats / Ryan Hefner

electron-github-asar-updater

v4.0.0

Published

electron asar updater

Downloads

4

Readme

electron-github-asar-updater

This package works after Electron app is packaged.

electron-github-asar-updater v2.x require Electron version >= 2.0.0

Usage

  1. Default

    // Electron main process
    const Updater = require('electron-github-asar-updater')
    
    /**
     * Write file
     * ${process.resourcesPath}/updater/index.js
     * ${process.resourcesPath}/updater/package.json
     */
    const updater = new Updater('githubUser/repoName', '{{prefix}}');
    
    (async function () {
      /**
       * Check latest github release.
       * 
       * Tag name must be "vX.X.X".
       * For example: v2.3.3
       * 
       * Asar zip name must be `{{prefix}}-${process.platform}-${process.arch}.zip`
       * For example: {{prefix}}-win32-ia32.zip {{prefix}}-linux-x64.zip
       * 
       * Full asset name example:
       * myapp-v2.3.3-win32-x64.zip
       * myapp-v2.3.3-win32-ia32.exe
       * myapp-v2.3.3-linux-x64.deb
       */
      await updater.check({
        /**
         * -1: ignore pre-release (default)
         * 0:  include pre-release
         * 1:  check prerelease only
         */
        prerelease: -1
      })
    
      const info = updater.getUpdateInfo()
      if (info) { // newer version found
           
        console.log(info)
        if (updater.isReadyToDownload()) { // exists `resources-${process.platform}-${process.arch}.zip`
          /**
           * Download `resources-${process.platform}.zip` and unzip to
           * `${process.resourcesPath}/.patch`
           */
          const downloadResult = await updater.download(({ name, current, max, loading }) => {
            /**
             * {
             *   name: string;
             *   current: number;
             *   max: number;
             *   loading: number;
             * }
             * 
             * do something, return void
             */
          })
    
          if (downloadResult) { // Success
            /**
             * 1. Rename `${process.resourcesPath}/updater` to `${process.resourcesPath}/app`
             * 2. Relaunch. Copy `${process.resourcesPath}/.patch/*` to `${process.resourcesPath}`
             * 3. Remove `${process.resourcesPath}/.patch`
             * 4. Rename `${process.resourcesPath}/app` to `${process.resourcesPath}/updater`
             * 5. Relaunch
             */ 
            updater.relaunch()
          } else {
            console.log('download aborted.')
          }
        }
      }
    })()
  2. Use custom updater executable

    // Electron main process
    const Updater = require('electron-github-asar-updater')
    
    // use custom updater executable
    const updater = new Updater('githubUser/repoName', '{{prefix}}', true);
    (async function () {
    
      await updater.check({
        prerelease: -1
      })
    
      const info = updater.getUpdateInfo()
      if (info) {
        if (updater.isReadyToDownload()) {
          const downloadResult = await updater.download(({ name, current, max, loading }) => {})
          if (downloadResult) {
            // run executable and exit app, relaunch app by your program
            require('child_process').spawn(/* ... */).unref()
            updater.relaunch() // just call app.exit()
          } else {
            console.log('download aborted.')
          }
        }
      }
    })()