Skip to content
This repository was archived by the owner on May 5, 2026. It is now read-only.

Commit 9807d4b

Browse files
committed
refactor(pwa): handle pwa install in manager
Signed-off-by: Kai Henseler <kai.henseler@strato.de>
1 parent b6467e5 commit 9807d4b

2 files changed

Lines changed: 23 additions & 27 deletions

File tree

‎src/lib/IONOS/components/notifications/NotificationBanner.svelte‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,11 @@
99
import Link from '$lib/IONOS/components/common/Link.svelte';
1010
import { NotificationType, type Notification } from '$lib/IONOS/stores/notifications';
1111
import { createEventDispatcher, getContext } from 'svelte';
12-
import { isIOSDevice, isSafari } from '$lib/IONOS/services/pwa';
1312
1413
const dispatch = createEventDispatcher();
1514
const i18n = getContext<Readable<I18Next>>('i18n');
1615
1716
export let notification: Notification;
18-
export let deferredPrompt: any = null;
19-
20-
const showIOSInstructions = isIOSDevice() && isSafari();
21-
22-
23-
const handlePWAInstall = () => {
24-
if (showIOSInstructions) {
25-
dispatch('showDialog');
26-
} else if (deferredPrompt) {
27-
deferredPrompt.prompt();
28-
deferredPrompt.userChoice.then((choiceResult: any) => {
29-
if (choiceResult.outcome === 'accepted') {
30-
dispatch('dismiss', { notification });
31-
}
32-
});
33-
}
34-
};
3517
</script>
3618

3719

‎src/lib/IONOS/components/notifications/NotificationManager.svelte‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import {
1414
shouldShowPWAPrompt,
1515
dismissPWAPrompt,
16-
triggerPWAInstall
16+
triggerPWAInstall,
17+
isIOSDevice,
18+
isSafari
1719
} from '$lib/IONOS/services/pwa';
1820
import { deferredPrompt, isPWAInstallable, setupGlobalPWAListener, clearDeferredPrompt } from '$lib/IONOS/stores/pwa-prompt';
1921
@@ -99,7 +101,7 @@
99101
actions: [{
100102
label: $i18n.t('Install', { ns: 'ionos' }),
101103
handler: () => {
102-
showPWADialog = true;
104+
handlePWAInstall();
103105
}
104106
}],
105107
dismissible: true,
@@ -108,34 +110,46 @@
108110
};
109111
110112
const handlePWAInstall = async () => {
111-
if ($deferredPrompt) {
113+
const showIOSInstructions = isIOSDevice() && isSafari();
114+
115+
if (showIOSInstructions) {
116+
showPWADialog = true;
117+
} else if ($deferredPrompt) {
112118
const accepted = await triggerPWAInstall($deferredPrompt);
113119
if (accepted) {
114120
clearDeferredPrompt();
121+
removeNotification({ type: NotificationType.PWA_INSTALL } as Notification);
115122
}
116123
}
117-
showPWADialog = false;
118-
removeNotification({ type: NotificationType.PWA_INSTALL } as Notification);
119124
};
120125
121126
const handlePWADialogDismiss = () => {
122127
showPWADialog = false;
123128
};
129+
130+
const handlePWADialogInstall = async () => {
131+
if ($deferredPrompt) {
132+
const accepted = await triggerPWAInstall($deferredPrompt);
133+
if (accepted) {
134+
clearDeferredPrompt();
135+
}
136+
}
137+
showPWADialog = false;
138+
removeNotification({ type: NotificationType.PWA_INSTALL } as Notification);
139+
};
124140
</script>
125141

126142
<div class="sticky top-0 flex flex-col w-full z-50">
127143
{#each $notifications as notification }
128144
<NotificationBanner
129145
{notification}
130-
deferredPrompt={$deferredPrompt}
131146
on:dismiss={dismissHandler}
132-
on:showDialog={showPWADialog = true }
133147
/>
134148
{/each}
135149
</div>
136150

137151
<PWAInstallDialog
138152
bind:show={showPWADialog}
139-
on:install={handlePWAInstall}
153+
on:install={handlePWADialogInstall}
140154
on:close={handlePWADialogDismiss}
141-
/>
155+
/>

0 commit comments

Comments
 (0)