Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 72d30c3

Browse files
feat: prompt user to reload when a new version is available
1 parent d9ae43b commit 72d30c3

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

studio/src/app/app-root.tsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Build, Component, Element, h, State} from '@stencil/core';
1+
import {Build, Component, Element, h, Listen, State} from '@stencil/core';
22

33
import {toastController} from '@ionic/core';
44

@@ -80,8 +80,35 @@ export class AppRoot {
8080
}
8181
}
8282

83+
@Listen('swUpdate', {target: 'window'})
84+
async onSWUpdate() {
85+
const registration = await navigator.serviceWorker.getRegistration();
86+
87+
if (!registration || !registration.waiting) {
88+
return;
89+
}
90+
91+
const toast: HTMLIonToastElement = await toastController.create({
92+
message: 'A new version is available, reload to update.',
93+
buttons: [
94+
{
95+
text: 'Reload',
96+
icon: 'refresh-circle-outline',
97+
handler: () => {
98+
registration.waiting.postMessage('skipWaiting');
99+
window.location.reload();
100+
},
101+
},
102+
],
103+
position: 'top',
104+
color: 'quaternary',
105+
});
106+
107+
await toast.present();
108+
}
109+
83110
private async toastError(error: string) {
84-
const popover: HTMLIonToastElement = await toastController.create({
111+
const toast: HTMLIonToastElement = await toastController.create({
85112
message: error,
86113
buttons: [
87114
{
@@ -94,11 +121,11 @@ export class AppRoot {
94121
duration: 6000,
95122
});
96123

97-
popover.onDidDismiss().then(() => {
124+
toast.onDidDismiss().then(() => {
98125
errorStore.state.error = undefined;
99126
});
100127

101-
await popover.present();
128+
await toast.present();
102129
}
103130

104131
private async navigate(params: NavParams) {

0 commit comments

Comments
 (0)