diff --git a/renderer/src/modules/updater.js b/renderer/src/modules/updater.js index 7514f508..1e65bfd3 100644 --- a/renderer/src/modules/updater.js +++ b/renderer/src/modules/updater.js @@ -134,6 +134,25 @@ export class CoreUpdater { } } +const semverRegex = /^[0-9]+\.[0-9]+\.[0-9]+$/; + +/** + * This works on basic semantic versioning e.g. "1.0.0". + * + * @param {string} currentVersion + * @param {string} content + * @returns {boolean} whether there is an update + */ +function semverComparator(currentVersion, remoteVersion) { + currentVersion = currentVersion.split(".").map((e) => {return parseInt(e);}); + remoteVersion = remoteVersion.split(".").map((e) => {return parseInt(e);}); + + if (remoteVersion[0] > currentVersion[0]) return true; + else if (remoteVersion[0] == currentVersion[0] && remoteVersion[1] > currentVersion[1]) return true; + else if (remoteVersion[0] == currentVersion[0] && remoteVersion[1] == currentVersion[1] && remoteVersion[2] > currentVersion[2]) return true; + return false; +} + class AddonUpdater { @@ -176,7 +195,10 @@ class AddonUpdater { if (this.pending.includes(filename)) return; const info = this.cache[path.basename(filename)]; if (!info) return; - const hasUpdate = info.version != currentVersion; + let hasUpdate = info.update > currentVersion; + if (semverRegex.test(info.version) && semverRegex.test(currentVersion)) { + hasUpdate = semverComparator(currentVersion, info.version); + } if (!hasUpdate) return; this.pending.push(filename); }