From 41b513e0245e5c354508ef26e1a4ec89e67e7598 Mon Sep 17 00:00:00 2001 From: Matjaž Črnko Date: Mon, 6 Nov 2023 15:48:27 +0100 Subject: PWA: use only server attributes for serviceWorkerUpdateInterval --- modern/src/UpdateController.tsx | 4 ++-- modern/src/common/util/preferences.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'modern/src') diff --git a/modern/src/UpdateController.tsx b/modern/src/UpdateController.tsx index 0f1b800b..991ea346 100644 --- a/modern/src/UpdateController.tsx +++ b/modern/src/UpdateController.tsx @@ -2,14 +2,14 @@ import { Snackbar, IconButton } from '@mui/material'; import RefreshIcon from '@mui/icons-material/Refresh'; import React from 'react' import { useTranslation } from './common/components/LocalizationProvider'; -import { useAttributePreference } from './common/util/preferences'; +import { useServerAttributePreference } from './common/util/preferences'; import { useRegisterSW } from 'virtual:pwa-register/react' // Based on https://vite-pwa-org.netlify.app/frameworks/react.html function UpdateController() { const t = useTranslation(); - const serviceWorkerUpdateInterval = useAttributePreference('serviceWorkerUpdateInterval', 3600000); + const serviceWorkerUpdateInterval = useServerAttributePreference('serviceWorkerUpdateInterval', 3600000); const { needRefresh: [needRefresh], diff --git a/modern/src/common/util/preferences.js b/modern/src/common/util/preferences.js index 229b6f17..0604d848 100644 --- a/modern/src/common/util/preferences.js +++ b/modern/src/common/util/preferences.js @@ -39,3 +39,10 @@ export const useAttributePreference = (key, defaultValue) => useSelector((state) } return defaultValue; }); + +export const useServerAttributePreference = (key, defaultValue) => useSelector((state) => { + if (containsProperty(state.session.server.attributes, key)) { + return state.session.server.attributes[key]; + } + return defaultValue; +}); \ No newline at end of file -- cgit v1.2.3