Checking if app needs update
This commit is contained in:
parent
7997138c5e
commit
677ac02835
|
@ -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 = () => {
|
|||
//<OsmFetch map={getMap} />
|
||||
// @ts-ignore
|
||||
<div class='ol-map' ref={target}>
|
||||
<Updater/>
|
||||
<Invitation />
|
||||
<Overlays map={getMap} />
|
||||
<Note />
|
||||
|
|
|
@ -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;
|
|
@ -0,0 +1 @@
|
|||
export { default } from './Updater';
|
Loading…
Reference in New Issue