From e8de5739fa0d634d63a0f4d187f86c87f95b1af3 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Sat, 16 Dec 2023 10:26:35 +0000 Subject: [PATCH] Resolve has Update button to stay hidden if error --- src/main/resources/static/js/githubVersion.js | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/resources/static/js/githubVersion.js b/src/main/resources/static/js/githubVersion.js index 35433f76..f2eb2f52 100644 --- a/src/main/resources/static/js/githubVersion.js +++ b/src/main/resources/static/js/githubVersion.js @@ -16,26 +16,33 @@ function compareVersions(version1, version2) { return 0; } + async function getLatestReleaseVersion() { - const url = "https://api.github.com/repos/Frooodle/Stirling-PDF/releases/latest"; - const response = await fetch(url); - const data = await response.json(); - return data.tag_name.substring(1); + const url = "https://api.github.com/repos/Frooodle/Stirling-PDF/releases/latest"; + try { + const response = await fetch(url); + 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() { - const latestVersion = await getLatestReleaseVersion(); - console.log("latestVersion=" + latestVersion) - console.log("currentVersion=" + currentVersion) - console.log("compareVersions(latestVersion, currentVersion) > 0)=" + compareVersions(latestVersion, currentVersion)) - if (latestVersion != null && latestVersion != "" && compareVersions(latestVersion, currentVersion) > 0) { - document.getElementById("update-btn").style.display = "block"; - console.log("visible") - } else { - document.getElementById("update-btn").style.display = "none"; - console.log("hidden") - } + // Initialize the update button as hidden + document.getElementById("update-btn").style.display = "none"; + + const latestVersion = await getLatestReleaseVersion(); + console.log("latestVersion=" + latestVersion) + console.log("currentVersion=" + currentVersion) + console.log("compareVersions(latestVersion, currentVersion) > 0)=" + compareVersions(latestVersion, currentVersion)) + if (latestVersion && compareVersions(latestVersion, currentVersion) > 0) { + document.getElementById("update-btn").style.display = "block"; + console.log("visible") + } else { + console.log("hidden") + } } checkForUpdate(); \ No newline at end of file