mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 11:02:27 +08:00
more reliably check for version numbers
This commit is contained in:
parent
47baa02bca
commit
48d53e276e
@ -527,6 +527,52 @@ function downloadSvg(nameWithoutExtension, svgContent) {
|
|||||||
document.body.removeChild(element);
|
document.body.removeChild(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two semantic version strings.
|
||||||
|
* Returns:
|
||||||
|
* 1 if v1 is greater than v2
|
||||||
|
* 0 if v1 is equal to v2
|
||||||
|
* -1 if v1 is less than v2
|
||||||
|
*
|
||||||
|
* @param {string} v1 First version string
|
||||||
|
* @param {string} v2 Second version string
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
function compareVersions(v1, v2) {
|
||||||
|
|
||||||
|
// Remove 'v' prefix and everything after dash if present
|
||||||
|
v1 = v1.replace(/^v/, '').split('-')[0];
|
||||||
|
v2 = v2.replace(/^v/, '').split('-')[0];
|
||||||
|
|
||||||
|
const v1parts = v1.split('.').map(Number);
|
||||||
|
const v2parts = v2.split('.').map(Number);
|
||||||
|
|
||||||
|
// Pad shorter version with zeros
|
||||||
|
while (v1parts.length < 3) v1parts.push(0);
|
||||||
|
while (v2parts.length < 3) v2parts.push(0);
|
||||||
|
|
||||||
|
// Compare major version
|
||||||
|
if (v1parts[0] !== v2parts[0]) {
|
||||||
|
return v1parts[0] > v2parts[0] ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare minor version
|
||||||
|
if (v1parts[1] !== v2parts[1]) {
|
||||||
|
return v1parts[1] > v2parts[1] ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare patch version
|
||||||
|
if (v1parts[2] !== v2parts[2]) {
|
||||||
|
return v1parts[2] > v2parts[2] ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isUpdateAvailable(latestVersion, currentVersion) {
|
||||||
|
return compareVersions(latestVersion, currentVersion) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
reloadFrontendApp,
|
reloadFrontendApp,
|
||||||
parseDate,
|
parseDate,
|
||||||
@ -567,5 +613,7 @@ export default {
|
|||||||
areObjectsEqual,
|
areObjectsEqual,
|
||||||
copyHtmlToClipboard,
|
copyHtmlToClipboard,
|
||||||
createImageSrcUrl,
|
createImageSrcUrl,
|
||||||
downloadSvg
|
downloadSvg,
|
||||||
|
compareVersions,
|
||||||
|
isUpdateAvailable
|
||||||
};
|
};
|
||||||
|
@ -333,7 +333,6 @@ export default class GlobalMenuWidget extends BasicWidget {
|
|||||||
|
|
||||||
const latestVersion = await this.fetchLatestVersion();
|
const latestVersion = await this.fetchLatestVersion();
|
||||||
this.updateAvailableWidget.updateVersionStatus(latestVersion);
|
this.updateAvailableWidget.updateVersionStatus(latestVersion);
|
||||||
this.$updateToLatestVersionButton.toggle(latestVersion > glob.triliumVersion);
|
|
||||||
this.$updateToLatestVersionButton.find(".version-text").text(`Version ${latestVersion} is available, click to download.`);
|
this.$updateToLatestVersionButton.find(".version-text").text(`Version ${latestVersion} is available, click to download.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { t } from "../../services/i18n.js";
|
import { t } from "../../services/i18n.js";
|
||||||
import BasicWidget from "../basic_widget.js";
|
import BasicWidget from "../basic_widget.js";
|
||||||
|
import utils from "../../services/utils.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div style="display: none;">
|
<div style="display: none;">
|
||||||
@ -34,6 +35,6 @@ export default class UpdateAvailableWidget extends BasicWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateVersionStatus(latestVersion) {
|
updateVersionStatus(latestVersion) {
|
||||||
this.$widget.toggle(latestVersion > glob.triliumVersion);
|
this.$widget.toggle(utils.isUpdateAvailable(latestVersion, glob.triliumVersion));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user