-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add App Version Update Button on Home page
- Loading branch information
Florian Jud
committed
May 17, 2024
1 parent
a671af3
commit 7dac10b
Showing
2 changed files
with
45 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import AutorenewIcon from '@mui/icons-material/Autorenew'; | ||
import { IconButton, Stack, Typography } from '@mui/material'; | ||
import packageJson from '../../../package.json'; | ||
import useNotification from '../../hooks/useNotification'; | ||
const AppVersion = () => { | ||
const { notifyContext } = useNotification(); | ||
const APPLICATION_VERSION = packageJson.version; | ||
|
||
/* | ||
Update service worker on new version | ||
*/ | ||
const updateServiceWorker = () => { | ||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker.ready | ||
.then((registration) => { | ||
registration.unregister().then(() => { | ||
window.location.reload(); | ||
notifyContext.addNotification('Deine App wurde aktualisiert', 'success'); | ||
}); | ||
}) | ||
.catch((error) => { | ||
notifyContext.addNotification('Ops da hat was nicht geklappt!', 'error'); | ||
console.error('Service Worker Error: ', error); | ||
}); | ||
} else { | ||
notifyContext.addNotification('Es wurde kein Update gefunden', 'info'); | ||
} | ||
}; | ||
|
||
return ( | ||
<Stack direction="row" justifyContent="space-between" alignItems="center" gap={0}> | ||
<Typography variant="caption" color="text.disabled"> | ||
Du nutzt die v{APPLICATION_VERSION}, auf Updates prüfen? | ||
</Typography> | ||
<IconButton aria-label="delete" size="small" onClick={updateServiceWorker}> | ||
<AutorenewIcon fontSize="inherit" /> | ||
</IconButton> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default AppVersion; |
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