Skip to content

Commit

Permalink
Prompt when there is an update (#889)
Browse files Browse the repository at this point in the history
* Prompt when there is an update

* Fix linter
  • Loading branch information
wooferzfg authored May 26, 2024
1 parent f8a75b3 commit 5dd6ef4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/ui/LiveSplit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ export class LiveSplit extends React.Component<Props, State> {
this.mediaQueryChanged = this.mediaQueryChanged.bind(this);
}

private notifyAboutUpdate(this: void)
{
toast.warn(
'A new version of LiveSplit One is available! Click here to reload.',
{
closeOnClick: true,
onClick: () => window.location.reload(),
},
);
}

public componentDidMount() {
this.scrollEvent = { handleEvent: (e: WheelEvent) => this.onScroll(e) };
window.addEventListener("wheel", this.scrollEvent);
Expand All @@ -218,6 +229,11 @@ export class LiveSplit extends React.Component<Props, State> {
}

this.handleAutomaticResize();

const { serviceWorker } = navigator;
if (serviceWorker) {
serviceWorker.addEventListener('controllerchange', this.notifyAboutUpdate);
}
}

public componentDidUpdate() {
Expand Down Expand Up @@ -245,6 +261,11 @@ export class LiveSplit extends React.Component<Props, State> {
// This is bound in the constructor
// eslint-disable-next-line @typescript-eslint/unbound-method
this.isDesktopQuery.removeEventListener("change", this.mediaQueryChanged);

const { serviceWorker } = navigator;
if (serviceWorker) {
serviceWorker.removeEventListener('controllerchange', this.notifyAboutUpdate);
}
}

public render() {
Expand Down

0 comments on commit 5dd6ef4

Please sign in to comment.