Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

rom1dep
Copy link

@rom1dep rom1dep commented Nov 5, 2024

No description provided.

@@ -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);

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

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.

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.

  1. Obtain major, minor, patch by splitting the version by "." with a max number of elements of 3.
  2. If the major of $b > a$, then $b$ is newer.
  3. If the minor of $b > a$, then $b$ is newer.
  4. If the patch of $b > a$, then $b$ is newer.
  5. Otherwise, $b$ is older or equal to $a$ (no popup needed).

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 :)

@perfectra1n
Copy link

perfectra1n commented Nov 9, 2024

Closing in favor of #574

@perfectra1n perfectra1n closed this Nov 9, 2024
@rom1dep rom1dep deleted the version_checking branch November 11, 2024 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants