-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PWA regularly check for service worker updates and automaticially reload the page #1188
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0daf321
fix: PWA regularly check for service worker updates and automaticiall…
jinzo d1c0292
PWA: Move to a Reload Prompt model - WIP
jinzo 31649a7
PWA: Forgot the setting translation
jinzo a5cf24f
PWA: Move ReloadPrompt to an initialized location, so that Attributes…
jinzo 7edda4c
PWA: Reload button styling to default
jinzo a0b14ad
PWA: cleanup
jinzo 257517f
PWA: Update check rework per feedback
jinzo ef888f5
PWA: Update wording
jinzo 46e9862
PWA: Add reference for vite-plugin-pwa
jinzo d369a2d
Update modern/src/UpdateCheckPrompt.tsx
jinzo ee80236
PWA: Replace reload button with an icon
jinzo f81bf48
PWA: Rename to UpdateController
jinzo 41b513e
PWA: use only server attributes for serviceWorkerUpdateInterval
jinzo 08f991b
PWA: linting
jinzo 93b8ec8
PWA: Remove the reference for type declarations
jinzo 85d5322
PWA: remove useServerAttributePreference and shorten the line/variabl…
jinzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Snackbar, Button } from '@mui/material'; | ||
import React from 'react' | ||
import { useTranslation } from './common/components/LocalizationProvider'; | ||
import { useAttributePreference } from './common/util/preferences'; | ||
import { useRegisterSW } from 'virtual:pwa-register/react' | ||
|
||
// Based on https://vite-pwa-org.netlify.app/frameworks/react.html | ||
function UpdateCheckPrompt() { | ||
const t = useTranslation(); | ||
|
||
const serviceWorkerUpdateInterval = useAttributePreference('serviceWorkerUpdateInterval', 3600000); | ||
|
||
const { | ||
needRefresh: [needRefresh], | ||
updateServiceWorker, | ||
} = useRegisterSW({ | ||
onRegisteredSW(swUrl, swRegistration) { | ||
if (serviceWorkerUpdateInterval > 0 && swRegistration) { | ||
setInterval(async () => { | ||
if (!(!swRegistration.installing && navigator)) { | ||
return; | ||
} | ||
|
||
if (('connection' in navigator) && !navigator.onLine) { | ||
return; | ||
} | ||
|
||
const newSW = await fetch(swUrl, { | ||
cache: 'no-store', | ||
headers: { | ||
'cache': 'no-store', | ||
'cache-control': 'no-cache', | ||
}, | ||
}); | ||
|
||
if (newSW?.status === 200) { | ||
await swRegistration.update(); | ||
} | ||
}, serviceWorkerUpdateInterval); | ||
} | ||
} | ||
}); | ||
|
||
return ( | ||
<Snackbar | ||
open={needRefresh} | ||
message={t('settingsUpdateAvailable')} | ||
action={( | ||
<Button onClick={() => updateServiceWorker(true)}> | ||
{t('settingsReload')} | ||
</Button> | ||
)} | ||
/> | ||
jinzo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
|
||
export default UpdateCheckPrompt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite-plugin-pwa/react" /> | ||
jinzo marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use an icon button? Like this one:
https://mui.com/material-ui/material-icons/?query=ref&selected=Refresh
It looks better and also we can remove one of the strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, did not even think about this.