Giter VIP home page Giter VIP logo

Comments (2)

dsheiko avatar dsheiko commented on July 21, 2024

But I do not use any library or framework. It's pure / Vanilla JavaScript. Async/await functions are part of JavaScript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

But if you peffer Promises, that is supposed to work either:

<!DOCTYPE html>
<html>
  <head>
    <title>Autoupdater Example (Script Strategy)</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>
  <body>
    <pre id="output"></pre>
    <script>
      const AutoUpdater = require( "nw-autoupdater" ),
            updater = new AutoUpdater( require( "./package.json" ), {
              strategy: "ScriptSwap"
            }),
            output =  document.querySelector( "#output" );

     
      output.innerHTML = `Application ver. ${nw.App.manifest.version}\n`;
      
      // Download/unpack update if any available
      updater.readRemoteManifest().then(( rManifest ) => {
        updater.checkNewVersion( rManifest ).then(( needsUpdate ) => {
          if ( !needsUpdate ) {
            output.innerHTML += `\nApp is up to date...`;
            return;
          }
          if ( !confirm( "New release is available. Do you want to upgrade?" ) ) {
            return;
          }
        });
        
         updater.download( rManifest ).then(( updateFile ) => {
           updater.unpack( updateFile ).then(() => {
             alert( `The application will automatically restart to finish installing the update` );
             updater.restartToSwap();
           });
         });
          
      }); 

      // Subscribe for progress events
      updater.on( "download", ( downloadSize, totalSize ) => {
        output.innerHTML = `Downloading...`;
        console.log( "download progress", Math.floor( downloadSize / totalSize * 100 ), "%" );
      });
      updater.on( "install", ( installFiles, totalFiles ) => {
        output.innerHTML = `Installing...\n`;
        console.log( "install progress", Math.floor( installFiles / totalFiles * 100 ), "%" );
      });


    </script>
  </body>
</html>

from nw-autoupdater.

Arti3DPlayer avatar Arti3DPlayer commented on July 21, 2024

cool, thanks. Will try your updater in our app:) Seems I'm not keeping pace with progress

from nw-autoupdater.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.