From 28424beb59a227a3289f6938a211abdd12b14cd6 Mon Sep 17 00:00:00 2001 From: Jason Pickering Date: Wed, 11 Dec 2024 14:27:10 +0100 Subject: [PATCH] Add app update info --- src/components/IntroPage.js | 40 +++++++++++++++++++++++++++++++++++++ webpack.config.js | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/components/IntroPage.js b/src/components/IntroPage.js index adb5fac..776cc36 100644 --- a/src/components/IntroPage.js +++ b/src/components/IntroPage.js @@ -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 = `

`; + + checkForAppUpdates().then((updateAvailable) => { + console.log("Update available: ", updateAvailable); + if (updateAvailable) { + this.innerHTML += "

App update is available. Please update the app from the App Management App!

"; + } + }); } } \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 21bd0b2..624e1ae 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -89,7 +89,7 @@ const webpackConfig = { proxy: { "/api/*": { "target": "http://localhost:8080/dhis", - "auth": "demo_en:District1#" + "auth": "admin:district" } } },