Skip to content

Commit

Permalink
properly fix versionNumberGt function
Browse files Browse the repository at this point in the history
  • Loading branch information
MarmadileManteater committed Oct 30, 2024
1 parent 80c8b29 commit fa2cbd9
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fa2cbd9

Please sign in to comment.