Skip to content

Commit

Permalink
Add first attempt to version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedith Mulongo committed Jul 5, 2024
1 parent 3f1eea7 commit 3f17306
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<!-- react components are rendered here -->
</div>
<script src="index.js"></script>
<script src="version_checker.js"></script>
</body>
</html>
39 changes: 39 additions & 0 deletions version_checker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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}`);
}
const json = await response.json();
return json.data;
}

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)

console.log("dataFrGit:")
console.log(dataFrGit)
console.log(gitVersion)
console.log(gitVersionSummary)
console.log(gitVersionSummary.includes(version))
if(!gitVersionSummary.includes(version)) {
window.dispatchEvent(new CustomEvent('versionchanged', { detail: version }));
}
}

function start() {
setInterval(gatherData, 8000);
}

window.addEventListener('versionchanged', function (e) {
alert('Unmacthed version. New UI version available!');
});

window.addEventListener('load', start);

0 comments on commit 3f17306

Please sign in to comment.