Resolve has Update button to stay hidden if error

This commit is contained in:
Anthony Stirling 2023-12-16 10:26:35 +00:00
parent 1b2734d99c
commit e8de5739fa

View File

@ -16,26 +16,33 @@ function compareVersions(version1, version2) {
return 0; return 0;
} }
async function getLatestReleaseVersion() { async function getLatestReleaseVersion() {
const url = "https://api.github.com/repos/Frooodle/Stirling-PDF/releases/latest"; const url = "https://api.github.com/repos/Frooodle/Stirling-PDF/releases/latest";
const response = await fetch(url); try {
const data = await response.json(); const response = await fetch(url);
return data.tag_name.substring(1); const data = await response.json();
return data.tag_name ? data.tag_name.substring(1) : "";
} catch (error) {
console.error("Failed to fetch latest version:", error);
return ""; // Return an empty string if the fetch fails
}
} }
async function checkForUpdate() { async function checkForUpdate() {
const latestVersion = await getLatestReleaseVersion(); // Initialize the update button as hidden
console.log("latestVersion=" + latestVersion) document.getElementById("update-btn").style.display = "none";
console.log("currentVersion=" + currentVersion)
console.log("compareVersions(latestVersion, currentVersion) > 0)=" + compareVersions(latestVersion, currentVersion)) const latestVersion = await getLatestReleaseVersion();
if (latestVersion != null && latestVersion != "" && compareVersions(latestVersion, currentVersion) > 0) { console.log("latestVersion=" + latestVersion)
document.getElementById("update-btn").style.display = "block"; console.log("currentVersion=" + currentVersion)
console.log("visible") console.log("compareVersions(latestVersion, currentVersion) > 0)=" + compareVersions(latestVersion, currentVersion))
} else { if (latestVersion && compareVersions(latestVersion, currentVersion) > 0) {
document.getElementById("update-btn").style.display = "none"; document.getElementById("update-btn").style.display = "block";
console.log("hidden") console.log("visible")
} } else {
console.log("hidden")
}
} }
checkForUpdate(); checkForUpdate();