-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benedith Mulongo
committed
Jul 8, 2024
1 parent
a6872e3
commit fd5ee15
Showing
1 changed file
with
21 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
import { data } from "/dist/version.js"; | ||
|
||
async function getData() { | ||
const url = `${process.env.API_URL}/api/v1.0/system/version`; | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`Response status: ${response.status}`); | ||
var done; | ||
function saveToLocalstorage() { | ||
const version = data.version; | ||
if (!done) { | ||
done = true; | ||
localStorage.setItem("version", version); | ||
} | ||
const json = await response.json(); | ||
return json.data; | ||
} | ||
|
||
function getLocalVersion() { | ||
const version = localStorage.getItem("version"); | ||
return version | ||
} | ||
|
||
async function gatherData() { | ||
const version = data.version; | ||
const dataFrGit = await getData(); | ||
const gitVersion = dataFrGit.version; | ||
const gitVersionSummary = dataFrGit.git_version; | ||
console.log("Data:"); | ||
console.log(version); | ||
const localVersion = await getLocalVersion(); | ||
console.log("localVersion:"); | ||
console.log(localVersion); | ||
|
||
console.log("dataFrGit:"); | ||
console.log(dataFrGit); | ||
console.log(gitVersion); | ||
console.log(gitVersionSummary); | ||
console.log(gitVersionSummary.includes(version)); | ||
if (!gitVersionSummary.includes(version)) { | ||
console.log("version:"); | ||
console.log(version); | ||
console.log(version.includes(localVersion)); | ||
if (!version.includes(localVersion)) { | ||
window.dispatchEvent( | ||
new CustomEvent("versionchanged", { detail: version }), | ||
); | ||
} | ||
} | ||
|
||
function start() { | ||
setInterval(gatherData, 8000); | ||
setInterval(gatherData, 600000); | ||
} | ||
|
||
window.addEventListener("versionchanged", function (e) { | ||
alert("Unmacthed version. New UI version available!"); | ||
}); | ||
|
||
|
||
saveToLocalstorage() | ||
window.addEventListener("load", start); |