From 677ac0283573d165c014175a738bba24f8fb860b Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Thu, 9 Mar 2023 21:00:56 +0100 Subject: [PATCH] Checking if app needs update --- src/components/map/Map.tsx | 2 ++ src/components/updater/Updater.tsx | 39 ++++++++++++++++++++++++++++++ src/components/updater/index.ts | 1 + 3 files changed, 42 insertions(+) create mode 100644 src/components/updater/Updater.tsx create mode 100644 src/components/updater/index.ts diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index 3cfafe1..96b514a 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -51,6 +51,7 @@ import Invitation, { searchInvitationInIntent, } from '../invitation'; import { returnOrUpdate } from 'ol/extent'; +import Updater from '../updater'; const [getState, setState] = createSignal({ lon: 0, @@ -311,6 +312,7 @@ const Map: Component = () => { // // @ts-ignore
+ diff --git a/src/components/updater/Updater.tsx b/src/components/updater/Updater.tsx new file mode 100644 index 0000000..d1033c4 --- /dev/null +++ b/src/components/updater/Updater.tsx @@ -0,0 +1,39 @@ +import { Alert } from '@suid/material'; +import { Component, createSignal, onCleanup, Show } from 'solid-js'; + +interface Props {} + +const Updater: Component = (props) => { + const [updateNeeded, setUpdateNeeded] = createSignal(false); + + const checkUpdate = async () => { + const response = await fetch( + 'https://dyomedea.app/assets/release/dyomedea.rel', + { + mode: 'cors', // no-cors, *cors, same-origin + cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached + credentials: 'same-origin', + } + ); + const latestRelease = (await response.text()).replace('\n', ''); + const currentRelease = import.meta.env.VITE_GIT_COMMIT_HASH; + console.log({ caller: 'checkUpdate', currentRelease, latestRelease }); + setUpdateNeeded(latestRelease !== currentRelease); + }; + + const intervalId = setInterval(checkUpdate, 30 * 1000); + + onCleanup(() => { + clearInterval(intervalId); + }); + + return ( + + + Please reload this page to update the application. + + + ); +}; + +export default Updater; diff --git a/src/components/updater/index.ts b/src/components/updater/index.ts new file mode 100644 index 0000000..e13b2ed --- /dev/null +++ b/src/components/updater/index.ts @@ -0,0 +1 @@ +export { default } from './Updater';