Skip to content

Commit

Permalink
Download working
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaredWilcurt committed Dec 31, 2023
1 parent 7e8f5d1 commit 872644d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
19 changes: 13 additions & 6 deletions api-type-definitions.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

/**
* @typedef {object} NEWWINDOW
* @property {string} [entry] The file to load in the window, like 'index.html'.
* @property {object} [window] Any NW.js window subfield options.
* [Docs](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#window-subfields)
* @property {string} [entry] The file to load in the window, like 'index.html'.
* @property {object} [window] Any NW.js window subfield options.
* [Docs](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#window-subfields)
*/

/**
Expand All @@ -52,9 +52,16 @@
*/

/**
* @typedef {object} DOWNLOADPROGRESS
* @property {number} percent Overall percent (between 0 to 1)
* @property {number} speed The download speed in bytes/sec (ex: 554732)
* @typedef {object} DOWNLOADPROGRESSTOTAL
* @property {number} bytes The total number of bytes downloaded so far
* @property {number} percent Overall percent (0-100), if server returned the total filesize, otherwise stays 0
* @property {number} speed The download speed in bytes/sec (ex: 554732)
*/

/**
* @typedef {object} DOWNLOADPROGRESS
* @property {array} details An array of details
* @property {DOWNLOADPROGRESSTOTAL} total The total download bytes, current speed, and percent
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions nw-testing/manual-testing.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function manualTesting () {
* Called when an update occurs during download/extract.
*
* @param {object} update Object containing percents
* @param {number} update.downloadProgress The download progress percent
* @param {object} update.downloadProgress The download progress percent
* @param {number} update.extractProgress The extract progress percent
*/
onUpdate: function ({ downloadProgress, extractProgress }) {
Expand All @@ -102,7 +102,7 @@ function manualTesting () {
console.log('Download progress:', downloadProgress);
}
if (extractProgress) {
console.log('Unzipping: ' + downloadProgress + '%');
console.log('Unzipping: ' + extractProgress + '%');
}
},
/**
Expand Down
17 changes: 11 additions & 6 deletions src/downloadZip.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ async function downloadZip (options, downloadUrl, latestRemote) {
const downloadOptions = {
existBehavior: 'overwrite',
maxRetry: options.autoUpdate.downloadRetries,
reportInterval: 1250
reportInterval: 1250,
httpOptions: {
headers: {
'User-Agent': 'nw-splasher-auto-update'
}
}
};

return new EasyDl(downloadUrl, zipFilePath, downloadOptions)
Expand All @@ -35,18 +40,18 @@ async function downloadZip (options, downloadUrl, latestRemote) {
/**
* Callback for when progress events occur while downloading zip file.
*
* @param {DOWNLOADPROGRESS} downloadProgress Details about the progress of the download
* @param {DOWNLOADPROGRESS} progress Details about the progress of the download
*/
function (downloadProgress) {
options.autoUpdate.onUpdate({ downloadProgress });
function (progress) {
options.autoUpdate.onUpdate({ downloadProgress: progress.total });
}
)
.wait()
.then((completed) => {
console.log('Downloaded?', completed);
console.log({ completed });
})
.catch((error) => {
console.log('[error]', error);
console.log({ error });
});
};

Expand Down

0 comments on commit 872644d

Please sign in to comment.