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-asar-updater

v1.1.3

Published

Handles Electron app.asar updates.

Downloads

4

Readme

What it is

A NodeJs module for Electron, that handles app.asar updates.

How it works (Read this first)

  • EAU (Electron Asar Updater) was built upon Electron Application Updater to handle the process of updating the app.asar file inside an Electron app ; it simply replaces the app.asar file (at /resources/) with the new one called "update.asar"!
  • The check for "updates" must by triggered by the application. EAU doesn't make any kind of periodic checks on its own.
  • EAU talks to an API (let's call it so) to tell it if there is a new update.
    • The API receives a request from EAU with the client's current version of the application (must be specified inside the application package.json file).
    • The API then responds with the new update, ... or simply false to abort.
    • If there's an update available the API should respond with the source for this update update.asar file.
    • EAU then downloads the .asar file, deletes the old app.asar and renames the update.asar to app.asar.

But why ? (use cases)

  • If you think these are too complicated to implement: https://www.npmjs.com/package/electron-updater http://electron.atom.io/docs/v0.33.0/api/auto-updater/
  • If you don't think it's reasonable to update the hole .app or .exe file (up to 100MB) when you're only changing one file (usually 40MB).

Installation

    $ npm install --save electron-asar-updater

Now, inside the main.js file, call it like this:

    const Electron = require('electron');
    const Application = Electron.app;
    const EAU = require('electron-asar-updater');
    const updateURL = 'http:// ....'; // The API EAU will talk to

    Application.on('ready', function(){
        // Initiate the module
        EAU.init({
            'api': updateURL
        });
        // Check for updates on startup
        mainWindow.webContents.on('did-finish-load', function() {
          mainWindow.webContents.executeJavaScript("checkForUpdates();");
        });
    });

That's it. Now, you can use EAU.check() to trigger the update process; EAU will first check for updates, if there was a new update, EAU will ask the user if he wants to update, then download it and replace the old app.asar. Inside a window you can use it like this:

    <script>
        var remote = null, app = null, EAU = null;

        window.onload = function() {
          remote = require('remote'),
          app = remote.require('app'),
          EAU = remote.require('electron-asar-updater');
        }

        window.checkForUpdates = function () {
          EAU.check(function(error){
            if(error){
              if(error === 'no_update_available') { return false; }
              alert(error);
              return false;
            }

            var apply = confirm("New Update Available.\nWould you like to update?");
            if (apply == true) {

                EAU.download(function(error){
                  if(error){
                    alert(error);
                    return false;
                  }
                  alert('App updated successfully! Restart it please.');
                  app.quit();
                });

            } else {
                return false;
            }

          });
        }
    </script>

API

Init( setup )

  • setup (object) The module setup

    • api (string) The URL EAU will call to check for updates.

    • logFile (string) [optional] The file to log the update process updates and errors to it, pass FALSE to omit logging . Defaults to "updater-log.txt".

    • requestOptions (object) [optional] The global options for the HTTP requests EAU will make to check for updates and download them. EAU uses the cool restler for these requests, and the requestOptions will be used for all the requests (the full options list). You can use this option to pass an accessToken or a username and password along with the request, or even send some extra data along with the request through the data property.

          EAU.init({
              'api': 'http:// ...',
              'requestOptions': {'accessToken': ..., 'data': {'group': 'friends'}}
          });    
    • callback (function) [optional] The callback that will be trigger at the end of the process, whether the update was a success or not. You can set the callback here, or you can pass it directly to check( ... ), I use the later option, to be able to console.log() the error in the DevTools.

        EAU.init({
            'callback': function(error){ ... }
        });

check( callback )

Will check for an update, if an update was found, will download it and install it! As mentioned, this method must be triggered, EAU wont check for updates on its own.

  • callback The update result callback. Check the installation section above for more details.

The update server

And I mean this in the most simple way possible. This server/API will receive one request, which is the check for updates, and will send one response of :

  • New update: {"last": " [the new version] ", "source": " [the .asar file url] "} EAU wont make any version comparisons, it will simply download the source url and extract it. So, you will need to handle this on your side, EAU sends (POST-type request) you the client's current version (as current), you can use this to send the correct update!
  • Any other value, to cancel the update

My current update server (for the app I described above) is:

    var desktop_app_version = '1.0.0';
    var desktop_app_URL = 'http://.../update.asar'

    this.app.post('/update', function (req, res) {
      if(req.body.current != desktop_app_version){
        res.write(JSON.stringify( {"last": desktop_app_version, "source": desktop_app_URL} ).replace(/[\/]/g, '\\/') );
      }else{
        res.write(JSON.stringify( {"last": desktop_app_version} ).replace(/[\/]/g, '\\/') );
      }
      res.end();
    });

  • Please contact me with any comments or open an issue.
  • The development of this module will be continued.

The MIT License (MIT) - Copyright (c) 2016 Whitesmith [email protected]