Checking if app needs update

This commit is contained in:
Eric van der Vlist 2023-03-09 21:00:56 +01:00
parent 7997138c5e
commit 677ac02835
3 changed files with 42 additions and 0 deletions

View File

@ -51,6 +51,7 @@ import Invitation, {
searchInvitationInIntent, searchInvitationInIntent,
} from '../invitation'; } from '../invitation';
import { returnOrUpdate } from 'ol/extent'; import { returnOrUpdate } from 'ol/extent';
import Updater from '../updater';
const [getState, setState] = createSignal({ const [getState, setState] = createSignal({
lon: 0, lon: 0,
@ -311,6 +312,7 @@ const Map: Component = () => {
//<OsmFetch map={getMap} /> //<OsmFetch map={getMap} />
// @ts-ignore // @ts-ignore
<div class='ol-map' ref={target}> <div class='ol-map' ref={target}>
<Updater/>
<Invitation /> <Invitation />
<Overlays map={getMap} /> <Overlays map={getMap} />
<Note /> <Note />

View File

@ -0,0 +1,39 @@
import { Alert } from '@suid/material';
import { Component, createSignal, onCleanup, Show } from 'solid-js';
interface Props {}
const Updater: Component<Props> = (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 (
<Show when={updateNeeded()}>
<Alert severity='warning'>
Please reload this page to update the application.
</Alert>
</Show>
);
};
export default Updater;

View File

@ -0,0 +1 @@
export { default } from './Updater';