|
23 | 23 | <span class="sr-only">Loading...</span>
|
24 | 24 | </div>
|
25 | 25 | </app-yt>
|
26 |
| - <script> |
| 26 | + <script> |
27 | 27 | const AutoUpdater = require( "nw-autoupdater" ),
|
28 | 28 | updater = new AutoUpdater( require( "./package.json" ) ),
|
29 | 29 | output = document.querySelector( "#output" ),
|
30 |
| - updateBar = document.getElementsByClassName("update-bar")[0].classList; |
| 30 | + updateBar = document.getElementsByClassName("update-bar")[0].classList; |
31 | 31 |
|
32 |
| - async function main(){ |
| 32 | + async function main(update){ |
33 | 33 | try {
|
34 | 34 | // Update copy is running to replace app with the update
|
35 | 35 | if ( updater.isSwapRequest() ) {
|
|
40 | 40 | await updater.restart();
|
41 | 41 | return;
|
42 | 42 | }
|
| 43 | + |
43 | 44 | // Download/unpack update if any available
|
44 | 45 | const rManifest = await updater.readRemoteManifest();
|
45 | 46 | const needsUpdate = await updater.checkNewVersion( rManifest );
|
|
51 | 52 | setTimeout(() => {
|
52 | 53 | updateBar.remove('active');
|
53 | 54 | }, 4000);
|
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + if (update) { |
| 59 | + output.innerHTML = `Preparing files...`; |
| 60 | + if (document.getElementById('update-buttons').hasChildNodes()) { |
| 61 | + var children = document.getElementById('update-buttons').childNodes; |
| 62 | + document.getElementById('update-buttons').removeChild(children[0]); |
| 63 | + document.getElementById('update-buttons').removeChild(children[0]); |
| 64 | + } |
| 65 | + return; |
54 | 66 | } else {
|
55 | 67 | output.innerHTML = `Update available...`;
|
56 | 68 | updateBar.add('active', 'update-av');
|
57 | 69 | initUpdate();
|
| 70 | + return; |
58 | 71 | }
|
| 72 | + |
| 73 | + // Subscribe for progress events |
| 74 | + updater.on( "download", ( downloadSize, totalSize ) => { |
| 75 | + output.innerHTML = `Downloading...`; |
| 76 | + console.log( "download progress", Math.floor( downloadSize / totalSize * 100 ), "%" ); |
| 77 | + }); |
| 78 | + updater.on( "install", ( installFiles, totalFiles ) => { |
| 79 | + output.innerHTML = `Installing...`; |
| 80 | + console.log( "install progress", Math.floor( installFiles / totalFiles * 100 ), "%" ); |
| 81 | + }); |
| 82 | + const updateFile = await updater.download( rManifest ); |
| 83 | + updater.unpack( updateFile ); |
| 84 | + updateAppSwap(); |
59 | 85 | } catch ( e ) {
|
60 | 86 | console.error( e );
|
61 | 87 | }
|
62 | 88 | }
|
63 |
| - |
64 |
| - function updateApp() { |
65 |
| - var rManifest = updater.readRemoteManifest(); |
66 |
| - |
67 |
| - // Subscribe for progress events |
68 |
| - updater.on( "download", ( downloadSize, totalSize ) => { |
69 |
| - output.innerHTML = `Downloading...`; |
70 |
| - console.log( "download progress", Math.floor( downloadSize / totalSize * 100 ), "%" ); |
71 |
| - }); |
72 |
| - updater.on( "install", ( installFiles, totalFiles ) => { |
73 |
| - output.innerHTML = `Installing...`; |
74 |
| - console.log( "install progress", Math.floor( installFiles / totalFiles * 100 ), "%" ); |
75 |
| - }); |
76 |
| - const updateFile = updater.download( rManifest ); |
77 |
| - updater.unpack( updateFile ); |
78 |
| - updateAppSwap(); |
79 |
| - } |
80 | 89 |
|
81 | 90 | function updateAppSwap() {
|
82 |
| - output.innerHTML = `The application will automatically restart to finish installing the update...`; |
83 | 91 | setTimeout(() => {
|
84 | 92 | updater.restartToSwap();
|
85 | 93 | }, 3000);
|
|
103 | 111 | btnUPD.innerHTML = 'Update';
|
104 | 112 | document.getElementById("update-buttons").appendChild(btnUPD);
|
105 | 113 |
|
106 |
| - btnUPD.onclick = updateApp; |
| 114 | + btnUPD.addEventListener("click", function(){ |
| 115 | + main(true); |
| 116 | + }); |
107 | 117 | }
|
108 | 118 |
|
109 |
| - main(); |
| 119 | + main(false); |
110 | 120 |
|
111 | 121 | </script>
|
112 | 122 | <script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
|
|
0 commit comments