Skip to content

Commit

Permalink
PWA: use only server attributes for serviceWorkerUpdateInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzo committed Nov 6, 2023
1 parent f81bf48 commit 41b513e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modern/src/UpdateController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
7 changes: 7 additions & 0 deletions modern/src/common/util/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Check failure on line 48 in modern/src/common/util/preferences.js

View workflow job for this annotation

GitHub Actions / build

Newline required at end of file but not found

0 comments on commit 41b513e

Please sign in to comment.