Skip to content

Commit

Permalink
Merge pull request #8 from dhis2/app-update
Browse files Browse the repository at this point in the history
Add app update info
  • Loading branch information
jason-p-pickering authored Dec 11, 2024
2 parents 1be47d5 + 28424be commit 837d3ce
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/components/IntroPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
import { d2Fetch } from "../js/utils.js";
export async function checkForAppUpdates() {
//Fetch a copy of th package.json from GitHub
const response = await fetch("https://raw.githubusercontent.com/dhis2/gf-adex-flow-app/main/package.json").then((response) => {
if (!response.ok) {
// Handle non-successful response
console.error("Error fetching package.json:", response.statusText);
return;
} else {
//convert the response to JSON
return response.json();
}
}
);

const remoteVersion = response.version;
console.log("Remote version is : ", remoteVersion);
//Get the current version of this apps API
const installedApps = await d2Fetch("apps/");
console.log("Installed apps: ", installedApps.length);
var updateAvailable = false;
installedApps.forEach((app) => {
if (app.key === "ADEx-Flow") {
console.log("App version is: ", app.version);
if (app.version !== remoteVersion) {
updateAvailable = true;
}
}
});

return updateAvailable;
}

export class IntroPage extends HTMLElement {
connectedCallback() {
this.innerHTML = `<h2 class="introduction" data-i18n="introduction.title"></h2>
<p class="introduction" data-i18n="introduction.content"></p>`;

checkForAppUpdates().then((updateAvailable) => {
console.log("Update available: ", updateAvailable);
if (updateAvailable) {
this.innerHTML += "<p>App update is available. Please update the app from the App Management App!</p>";
}
});
}
}
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const webpackConfig = {
proxy: {
"/api/*": {
"target": "http://localhost:8080/dhis",
"auth": "demo_en:District1#"
"auth": "admin:district"
}
}
},
Expand Down

0 comments on commit 837d3ce

Please sign in to comment.