Closed Arti3DPlayer closed 7 years ago
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>
cool, thanks. Will try your updater in our app:) Seems I'm not keeping pace with progress
Please provide pure javascript example... Is this possible ?