diff --git a/main.js b/main.js index 3f836ccde834e957e9b0d6523bace644706261da..7bcc982e912591e2a4023a56ab44c4fc3840c0a6 100644 --- a/main.js +++ b/main.js @@ -50,6 +50,24 @@ function createWindow () { lookForUpdates(); }; +/** + * Compares semver strings + * @see https://github.com/substack/semver-compare + */ +function semverCompare(a, b) { + var pa = a.split('.'); + var pb = b.split('.'); + for (var i = 0; i < 3; i++) { + var na = Number(pa[i]); + var nb = Number(pb[i]); + if (na > nb) return 1; + if (nb > na) return -1; + if (!isNaN(na) && isNaN(nb)) return 1; + if (isNaN(na) && !isNaN(nb)) return -1; + } + return 0; +} + /** * Calls the Cassiopee update server to check for available updates; * if so, displays a desktop notification which, if clicked, will @@ -97,7 +115,7 @@ const lookForUpdates = function() { response.on('data', (chunk) => { const data = JSON.parse(chunk); // compare current version to latest version - if (data.latest && data.latest > version) { + if (data.latest && semverCompare(data.latest, version) == 1) { // get download link for latest version, depending on platform if (data[data.latest] && data[data.latest][platform]) { const latestVersionURL = URL + data[data.latest][platform];