Skip to content

Commit dae714b

Browse files
leomp12claude
andcommitted
fix(storefront): Close notification popup quickly after user response
Popup now closes within 2 seconds maximum after user accepts or denies browser notifications, even if Firebase activation fails or takes longer. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ac4bc99 commit dae714b

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

packages/storefront/src/lib/composables/use-notification-permission.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,25 @@ const useNotificationPermission = (props: Props = {}) => {
3838
return;
3939
}
4040
isRequesting.value = true;
41-
try {
42-
const token = await registerFn();
43-
if (token) {
44-
if (onTokenReceived) {
45-
await onTokenReceived(token);
41+
const registrationPromise = (async () => {
42+
try {
43+
const token = await registerFn();
44+
if (token) {
45+
if (onTokenReceived) {
46+
await onTokenReceived(token);
47+
}
48+
localStorage.removeItem('notification-prompt-dismissed');
4649
}
47-
isVisible.value = false;
48-
localStorage.removeItem('notification-prompt-dismissed');
50+
} catch (error) {
51+
console.error('Error enabling notifications:', error);
4952
}
50-
} catch (error) {
51-
console.error('Error enabling notifications:', error);
52-
} finally {
53-
isRequesting.value = false;
54-
}
53+
})();
54+
const timeoutPromise = new Promise<void>((resolve) => {
55+
setTimeout(resolve, 2000);
56+
});
57+
await Promise.race([registrationPromise, timeoutPromise]);
58+
isVisible.value = false;
59+
isRequesting.value = false;
5560
};
5661

5762
const dismiss = () => {

0 commit comments

Comments
 (0)