Fix: webui notify update, state not updating when new release available
- commit
- 03f62a824c7781bbba28c3ec4c61c998b686facc
- author
- bnema · · 2023-11-07 09:47 UTC
- parent
- f751149
- signature
- unsigned
1 file · +12 -12
M internal/webui/public/assets/js/custom.js +12 -12
| @@ -1,21 +1,16 @@ | |||
| 1 | 1 | function initializeVersionCheck() { | |
| 2 | + | // Dummy data for the remote version (as if fetched from a server) | |
| 2 | 3 | const updateStrTemplate = "New version %VERSION% available, consider pulling the latest image"; | |
| 3 | 4 | ||
| 4 | - | const checkVersion = (versionData) => { | |
| 5 | - | const currentVersion = document.getElementById("actual-version").textContent.trim(); | |
| 5 | + | const checkVersion = (versionData, currentVersion) => { | |
| 6 | 6 | const fetchedVersionNumber = versionData?.amd64?.name.match(/\d+\.\d+\.\d+/)?.[0]; | |
| 7 | 7 | ||
| 8 | - | if (!fetchedVersionNumber) { | |
| 9 | - | console.log("Dev mode detected, skipping version check."); | |
| 10 | - | return; | |
| 11 | - | } | |
| 12 | - | ||
| 13 | 8 | if (currentVersion !== fetchedVersionNumber) { | |
| 14 | 9 | const updateStr = updateStrTemplate.replace("%VERSION%", fetchedVersionNumber); | |
| 15 | 10 | console.log(updateStr); | |
| 16 | 11 | const updateElement = document.getElementById("update-available"); | |
| 17 | 12 | updateElement.title = updateStr; | |
| 18 | - | updateElement.removeAttribute("hidden"); | |
| 13 | + | updateElement.toggleAttribute("hidden", false); | |
| 19 | 14 | updateElement.classList.remove("hidden"); // Remove the Tailwind `hidden` class | |
| 20 | 15 | updateElement.classList.add("block"); // Add the Tailwind `block` class | |
| 21 | 16 | } else { | |
| @@ -23,20 +18,25 @@ function initializeVersionCheck() { | |||
| 23 | 18 | } | |
| 24 | 19 | }; | |
| 25 | 20 | ||
| 26 | - | const fetchVersionInfo = () => { | |
| 21 | + | const fetchVersionInfo = (currentVersion) => { | |
| 27 | 22 | fetch("https://gordon-proxy.bnema.dev/version") | |
| 28 | 23 | .then((response) => response.json()) | |
| 29 | - | .then(checkVersion) | |
| 24 | + | .then((versionData) => checkVersion(versionData, currentVersion)) | |
| 30 | 25 | .catch((error) => console.error("Error fetching version:", error)); | |
| 31 | 26 | }; | |
| 32 | 27 | ||
| 33 | 28 | const init = () => { | |
| 34 | - | const currentVersion = document.getElementById("actual-version").textContent.trim(); | |
| 29 | + | const currentVersionElement = document.getElementById("actual-version"); | |
| 30 | + | if (!currentVersionElement) { | |
| 31 | + | console.log("Error: #actual-version element not found."); | |
| 32 | + | return; | |
| 33 | + | } | |
| 34 | + | const currentVersion = currentVersionElement.textContent.trim(); | |
| 35 | 35 | if (!currentVersion) { | |
| 36 | 36 | console.log("Dev mode detected, skipping version check."); | |
| 37 | 37 | return; | |
| 38 | 38 | } | |
| 39 | - | fetchVersionInfo(); | |
| 39 | + | fetchVersionInfo(currentVersion); | |
| 40 | 40 | }; | |
| 41 | 41 | ||
| 42 | 42 | init(); | |
| @@ -1,21 +1,16 @@ | |||||
| 1 | function initializeVersionCheck() { | 1 | function initializeVersionCheck() { | ||
| 2 | + | // Dummy data for the remote version (as if fetched from a server) | |||
| 2 | const updateStrTemplate = "New version %VERSION% available, consider pulling the latest image"; | 3 | const updateStrTemplate = "New version %VERSION% available, consider pulling the latest image"; | ||
| 3 | 4 | ||||
| 4 | - | const checkVersion = (versionData) => { | 5 | + | const checkVersion = (versionData, currentVersion) => { |
| 5 | - | const currentVersion = document.getElementById("actual-version").textContent.trim(); | |||
| 6 | const fetchedVersionNumber = versionData?.amd64?.name.match(/\d+\.\d+\.\d+/)?.[0]; | 6 | const fetchedVersionNumber = versionData?.amd64?.name.match(/\d+\.\d+\.\d+/)?.[0]; | ||
| 7 | 7 | ||||
| 8 | - | if (!fetchedVersionNumber) { | |||
| 9 | - | console.log("Dev mode detected, skipping version check."); | |||
| 10 | - | return; | |||
| 11 | - | } | |||
| 12 | - | ||||
| 13 | if (currentVersion !== fetchedVersionNumber) { | 8 | if (currentVersion !== fetchedVersionNumber) { | ||
| 14 | const updateStr = updateStrTemplate.replace("%VERSION%", fetchedVersionNumber); | 9 | const updateStr = updateStrTemplate.replace("%VERSION%", fetchedVersionNumber); | ||
| 15 | console.log(updateStr); | 10 | console.log(updateStr); | ||
| 16 | const updateElement = document.getElementById("update-available"); | 11 | const updateElement = document.getElementById("update-available"); | ||
| 17 | updateElement.title = updateStr; | 12 | updateElement.title = updateStr; | ||
| 18 | - | updateElement.removeAttribute("hidden"); | 13 | + | updateElement.toggleAttribute("hidden", false); |
| 19 | updateElement.classList.remove("hidden"); // Remove the Tailwind `hidden` class | 14 | updateElement.classList.remove("hidden"); // Remove the Tailwind `hidden` class | ||
| 20 | updateElement.classList.add("block"); // Add the Tailwind `block` class | 15 | updateElement.classList.add("block"); // Add the Tailwind `block` class | ||
| 21 | } else { | 16 | } else { | ||
| @@ -23,20 +18,25 @@ function initializeVersionCheck() { | |||||
| 23 | } | 18 | } | ||
| 24 | }; | 19 | }; | ||
| 25 | 20 | ||||
| 26 | - | const fetchVersionInfo = () => { | 21 | + | const fetchVersionInfo = (currentVersion) => { |
| 27 | fetch("https://gordon-proxy.bnema.dev/version") | 22 | fetch("https://gordon-proxy.bnema.dev/version") | ||
| 28 | .then((response) => response.json()) | 23 | .then((response) => response.json()) | ||
| 29 | - | .then(checkVersion) | 24 | + | .then((versionData) => checkVersion(versionData, currentVersion)) |
| 30 | .catch((error) => console.error("Error fetching version:", error)); | 25 | .catch((error) => console.error("Error fetching version:", error)); | ||
| 31 | }; | 26 | }; | ||
| 32 | 27 | ||||
| 33 | const init = () => { | 28 | const init = () => { | ||
| 34 | - | const currentVersion = document.getElementById("actual-version").textContent.trim(); | 29 | + | const currentVersionElement = document.getElementById("actual-version"); |
| 30 | + | if (!currentVersionElement) { | |||
| 31 | + | console.log("Error: #actual-version element not found."); | |||
| 32 | + | return; | |||
| 33 | + | } | |||
| 34 | + | const currentVersion = currentVersionElement.textContent.trim(); | |||
| 35 | if (!currentVersion) { | 35 | if (!currentVersion) { | ||
| 36 | console.log("Dev mode detected, skipping version check."); | 36 | console.log("Dev mode detected, skipping version check."); | ||
| 37 | return; | 37 | return; | ||
| 38 | } | 38 | } | ||
| 39 | - | fetchVersionInfo(); | 39 | + | fetchVersionInfo(currentVersion); |
| 40 | }; | 40 | }; | ||
| 41 | 41 | ||||
| 42 | init(); | 42 | init(); | ||