Skip to content

Commit

Permalink
Skip update prompts in invalid situations
Browse files Browse the repository at this point in the history
  • Loading branch information
wooferzfg committed Jun 7, 2024
1 parent 6f8056c commit ed59380
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ui/launcher.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import 'react-toggle/style.css';

export default class Launcher extends React.PureComponent {
static notifyAboutUpdate() {
const { serviceWorker } = navigator;
if (_.isNil(serviceWorker) || _.isNil(serviceWorker.controller)) {
// Don't prompt for update when service worker gets removed
return;
}

toast.warn(
'A new version of the tracker is available! Click here to reload.',
{
Expand Down Expand Up @@ -56,15 +62,16 @@ export default class Launcher extends React.PureComponent {
componentDidMount() {
const { serviceWorker } = navigator;

if (serviceWorker) {
if (!_.isNil(serviceWorker) && !_.isNil(serviceWorker.controller)) {
// Don't prompt for update when there was no service worker previously installed
serviceWorker.addEventListener('controllerchange', Launcher.notifyAboutUpdate);
}
}

componentWillUnmount() {
const { serviceWorker } = navigator;

if (serviceWorker) {
if (!_.isNil(serviceWorker)) {
serviceWorker.removeEventListener('controllerchange', Launcher.notifyAboutUpdate);
}
}
Expand Down

0 comments on commit ed59380

Please sign in to comment.