-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd856a4
commit 8e5d00b
Showing
12 changed files
with
236 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @file Used for manually testing the code | ||
* @author TheJaredWilcurt | ||
* @file Used for manually testing the code | ||
*/ | ||
|
||
const library = require('./index.js'); | ||
const semver = require('semver'); | ||
|
||
const options = { | ||
let options = { | ||
autoUpdate: { | ||
versionUrl: 'https://api.github.com/repos/scout-app/scout-app/releases', | ||
confirmNewVersion: function (response, latestLocal) { | ||
|
@@ -27,4 +26,162 @@ const options = { | |
} | ||
}; | ||
|
||
options = { | ||
// OPTIONAL: defaults to true | ||
verbose: true, | ||
/** | ||
* OPTIONAL: console.error is called by default if verbose: true. | ||
* | ||
* Your own custom logging function called with helpful warning/error | ||
* messages from the internal validators. Only used if verbose: true. | ||
* | ||
* @param {string} message The human readable warning/error message | ||
* @param {object} error Sometimes an error or options object is passed | ||
*/ | ||
customLogger: function (message, error) { | ||
console.log('customLogger', message, error); | ||
}, | ||
splasher: { | ||
/** | ||
* The websocket port the splash screen window listens on. When your main app window | ||
* loads, it will use the same port to signal the splash screen to close itself. | ||
*/ | ||
port: 4443, | ||
/** | ||
* Time in ms to wait after the new window is launched before auto-closing | ||
* splash screen if a signal is not recieved to close sooner. Send -1 to | ||
* only close if signaled via the websocket port. | ||
*/ | ||
closeSplashAfter: 3000 | ||
}, | ||
autoUpdate: { | ||
/** | ||
* NW.js Splasher Auto Update will make a network request to the versionUrl, | ||
* then pass the response into the confirmNewVersion and downloadPath | ||
* callback functions you provide. | ||
*/ | ||
// This is an example, you can put whatever URL you want here | ||
versionUrl: 'https://api.github.com/repos/scout-app/scout-app/releases', | ||
/** | ||
* Check if the latest remote version is newer than the latest local version. | ||
* If a new version is available, return the new version number to begin the | ||
* download/extract. If no new version exists, then return false and the latest | ||
* local version will be opened in a new window and the splash screen closed. | ||
* | ||
* @param {string} response The network respone from versionUrl | ||
* @param {string} latestLocal The latest downloaded version, or undefined if not present | ||
* @return {string} The new version number (continue to download zip), or false (open current version) | ||
*/ | ||
confirmNewVersion: function (response, latestLocal) { | ||
console.log('confirmNewVersion'); | ||
const latestRemote = response.data[0].tag_name.replace('v', ''); | ||
const updateAvailable = semver.gt(latestRemote, latestLocal); | ||
if (updateAvailable) { | ||
return latestRemote; | ||
} | ||
return false; | ||
}, | ||
/** | ||
* Called after hitting the versionUrl with the response. | ||
* Must return a url to a ZIP file to be downloaded/extracted | ||
* | ||
* @param {string} response The response body from the network request | ||
* @return {string} A url to a ZIP file to be downloaded | ||
*/ | ||
downloadPath: function (response) { | ||
console.log('downloadPath'); | ||
//This is just an example, you can put any logic you want here | ||
response = JSON.parse(response); | ||
return response.latest.downloadUrl; | ||
}, | ||
// If the download or extract fails, we will retry n times before stopping | ||
downloadRetries: 3, | ||
extractRetries: 3, | ||
/** | ||
* Called when an update occurs during download/extract. | ||
* | ||
* @param {object} update Object containing percents | ||
* @param {number} update.downloadProgress The download progress percent | ||
* @param {number} update.extractProgress The extract progress percent | ||
*/ | ||
onUpdate: function ({ downloadProgress, extractProgress }) { | ||
console.log('onUpdate'); | ||
//This is just an example, you can put any logic you want here | ||
if (downloadProgress) { | ||
console.log('Download progress: ' + downloadProgress + '%'); | ||
} | ||
if (extractProgress) { | ||
console.log('Unzipping: ' + downloadProgress + '%'); | ||
} | ||
}, | ||
/** | ||
* Optional function. You can run any code to validate | ||
* that the downloaded zip matches expecations. | ||
* If it does return true. If you return false, then | ||
* nwSplasherAutoUpdate will retry or stop running. | ||
* | ||
* @param {string} pathToZip File path to the downloaded zip file | ||
* @return {Boolean} true = continue, false = retry/stop | ||
Check warning on line 124 in manual-testing.js GitHub Actions / build (18.x)
|
||
*/ | ||
validateZip: function (pathToZip) { | ||
console.log('validateZip'); | ||
//This is just an example, you can put any logic you want here | ||
return true; | ||
}, | ||
/** | ||
* Optional function. You can run any code to validate | ||
* that the files extracted from the zip match your | ||
* expecations. If they do return true. If you return false, | ||
* then nwSplasherAutoUpdate will retry or stop running. | ||
* | ||
* @param {string} pathToExtract File path to the downloaded zip file | ||
* @return {Boolean} true = continue, false = retry/stop | ||
Check warning on line 138 in manual-testing.js GitHub Actions / build (18.x)
|
||
*/ | ||
validateExtract: function (pathToExtract) { | ||
console.log('validateExtract'); | ||
//This is just an example, you can put any logic you want here | ||
return true; | ||
}, | ||
/** | ||
* When download or extract fails, but we haven't | ||
* exhausted all retries yet, this is called. | ||
* | ||
* @param {string} message Human readable warning message | ||
*/ | ||
onRetry: function (message) { | ||
//This is just an example, you can put any logic you want here | ||
console.log('onRetry', message); | ||
}, | ||
/** | ||
* Called when an error is encountered that ended execution | ||
* prematurely. Such as failing to download or extract after | ||
* all retries were exhausted. | ||
* | ||
* @param {string} errorMessage Human readable error message | ||
* @param {object} error Detailed error information if available | ||
*/ | ||
onError: function (errorMessage, error) { | ||
//This is just an example, you can put any logic you want here | ||
console.log('onError', errorMessage, error); | ||
}, | ||
/** | ||
* Called just prior to opening the new window | ||
* and closing the splash screen. | ||
*/ | ||
onComplete: function () { | ||
console.log('onComplete'); | ||
} | ||
}, | ||
newWindow: { | ||
// The file from the extracted zip to load in the new window | ||
entry: 'index.html', | ||
// Any NW.js window subfield options: docs.nwjs.io/en/latest/References/Manifest%20Format/#window-subfields | ||
window: { | ||
min_width: 400, | ||
min_height: 250 | ||
} | ||
} | ||
}; | ||
|
||
|
||
library.downloadLatestAppAndOpenWindowInBackground(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @file Checks the most recent local version of the app | ||
*/ | ||
|
||
const { OPTIONS } = require('../api-type-definitions.js'); | ||
|
||
const helpers = require('./helpers.js'); | ||
|
||
/** | ||
* | ||
* | ||
* @param {OPTIONS} options User's validated options | ||
* @return {Promise} . | ||
*/ | ||
async function getLatestLocal (options) { | ||
return new Promise((resolve, reject) => { | ||
let latestLocal = '0.0.0'; | ||
if (latestLocal) { | ||
resolve(latestLocal); | ||
} else { | ||
helpers.throwError(options, 'Error getting latest local version number', error); | ||
reject(); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = getLatestLocal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @file Vitest setup file | ||
* @author TheJaredWilcurt | ||
* @file Vitest setup file | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters