From fa2cbd967476187a963401904ac15a1777eb90fa Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 30 Oct 2024 13:08:23 -0400 Subject: [PATCH] properly fix `versionNumberGt` function --- src/renderer/App.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/renderer/App.js b/src/renderer/App.js index cd55aef81a6fe..946f56858dac4 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -273,7 +273,28 @@ export default defineComponent({ const message = this.$t('Version $ is now available! Click for more details') this.updateBannerMessage = message.replace('$', tagName) function versionNumberGt(versionA, versionB) { - return [versionA, versionB].sort().at(-1) === versionA + const partsA = versionA.split('.') + const partsB = versionB.split('.') + if (partsA.length > partsB.length) { + return true + } else if (partsB.length > partsA.length) { + return false + } else { + const partComparisons = partsA.map(a => false) + let oneLeftmostLt = false + let oneGt = false + for (let i = 0; i < partsA.length; i++) { + partComparisons[i] = parseInt(partsA[i]) === parseInt(partsB[i]) ? 'eq' : parseInt(partsA[i]) > parseInt(partsB[i]) ? 'gt' : 'lt' + if (partComparisons[i] === 'gt') { + oneGt = true + } + if (partComparisons[i] === 'lt' && !oneGt) { + oneLeftmostLt = true + } + } + const thereIsAGtBeforeALt = !oneLeftmostLt + return oneGt && thereIsAGtBeforeALt + } } if (versionNumberGt(json[0].name, packageDetails.version)) { this.showUpdatesBanner = true