forked from dsheiko/nw-autoupdater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
56 lines (49 loc) · 1.86 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!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" );
async function main(){
try {
// Download/unpack update if any available
const rManifest = await updater.readRemoteManifest();
const needsUpdate = await updater.checkNewVersion( rManifest );
if ( !needsUpdate ) {
output.innerHTML += `\nApp is up to date...`;
return;
}
if ( !confirm( "New release is available. Do you want to upgrade?" ) ) {
return;
}
// 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 ), "%" );
});
const updateFile = await updater.download( rManifest );
await updater.unpack( updateFile );
alert( `The application will automatically restart to finish installing the update` );
await updater.restartToSwap();
} catch ( e ) {
console.error( e );
}
}
output.innerHTML = `Application ver. ${nw.App.manifest.version}\n`;
main();
</script>
</body>
</html>