-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: more reliably detect new versions #554
Conversation
@@ -333,7 +333,7 @@ export default class GlobalMenuWidget extends BasicWidget { | |||
|
|||
const latestVersion = await this.fetchLatestVersion(); | |||
this.updateAvailableWidget.updateVersionStatus(latestVersion); | |||
this.$updateToLatestVersionButton.toggle(latestVersion > glob.triliumVersion); | |||
this.$updateToLatestVersionButton.toggle((Number(latestVersion) > Number(glob.triliumVersion)) ?? false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typecasting to number doesn't directly work. I believe we have to compare each version component (major, minor, patch) individually.
> Number("1.2.11") > Number("1.2.10")
false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could implement another library meant for exactly this with:
import * as semver from 'semver';
this.$updateToLatestVersionButton.toggle(semver.gt(latestVersion, glob.triliumVersion));
But I'm not sure if we want to add another lib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with adding a new library is that we are here at the client level so it would involve a bit of effort to add it. I would personally only extract the version comparison algorithm, since I think it's not that difficult to implement.
- Obtain major, minor, patch by splitting the version by "." with a max number of elements of 3.
- If the major of
$b > a$ , then$b$ is newer. - If the minor of
$b > a$ , then$b$ is newer. - If the patch of
$b > a$ , then$b$ is newer. - Otherwise,
$b$ is older or equal to$a$ (no popup needed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the function that you're looking for:
function compareVersions(v1, v2) {
const v1Parts = v1.split('.').map(Number);
const v2Parts = v2.split('.').map(Number);
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
const part1 = v1Parts[i] || 0;
const part2 = v2Parts[i] || 0;
if (part1 > part2) return 1;
if (part1 < part2) return -1;
}
return 0;
}
Let me know if you wanna toss this in @rom1dep, or if you'd prefer if I did it :)
Closing in favor of #574 |
No description provided.