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,24 +16,31 @@ 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";
try {
const response = await fetch(url); const response = await fetch(url);
const data = await response.json(); const data = await response.json();
return data.tag_name.substring(1); 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() {
// Initialize the update button as hidden
document.getElementById("update-btn").style.display = "none";
const latestVersion = await getLatestReleaseVersion(); const latestVersion = await getLatestReleaseVersion();
console.log("latestVersion=" + latestVersion) console.log("latestVersion=" + latestVersion)
console.log("currentVersion=" + currentVersion) console.log("currentVersion=" + currentVersion)
console.log("compareVersions(latestVersion, currentVersion) > 0)=" + compareVersions(latestVersion, currentVersion)) console.log("compareVersions(latestVersion, currentVersion) > 0)=" + compareVersions(latestVersion, currentVersion))
if (latestVersion != null && latestVersion != "" && compareVersions(latestVersion, currentVersion) > 0) { if (latestVersion && compareVersions(latestVersion, currentVersion) > 0) {
document.getElementById("update-btn").style.display = "block"; document.getElementById("update-btn").style.display = "block";
console.log("visible") console.log("visible")
} else { } else {
document.getElementById("update-btn").style.display = "none";
console.log("hidden") console.log("hidden")
} }
} }