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

Commit b7b51f6

Browse files
Merge pull request #868 from deckgo/reload-sw
feat: prompt user to reload when an update is available
2 parents d9ae43b + ce845ea commit b7b51f6

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
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) {

studio/src/app/pages/core/app-signin/app-signin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export class AppSignIn {
298298

299299
private renderMsg() {
300300
return [
301-
<h1 class="ion-text-center ion-padding-start ion-padding-end">Oh, hi! Good to have you.</h1>,
301+
<h1 class="ion-text-center ion-padding-start ion-padding-end">Oh, hi 👋! Good to have you.</h1>,
302302
<p class="ion-text-center ion-padding">Sign in to unleash all features of the editor and to share your presentation online.</p>,
303303
];
304304
}

0 commit comments

Comments
 (0)