diff --git a/LittleShop/wwwroot/js/notifications.js b/LittleShop/wwwroot/js/notifications.js index d1cad80..868519f 100644 --- a/LittleShop/wwwroot/js/notifications.js +++ b/LittleShop/wwwroot/js/notifications.js @@ -113,7 +113,17 @@ class AdminNotificationManager { sessionStorage.setItem('notificationPromptDismissed', 'true'); } catch (error) { console.error('Failed to enable notifications:', error); - this.showNotificationError('Failed to enable notifications. Please try again.'); + + // Check if it's a timeout error - if so, dismiss the prompt + if (error.message && error.message.includes('timed out')) { + promptDiv.remove(); + sessionStorage.setItem('notificationPromptDismissed', 'true'); + localStorage.setItem('pushNotificationDeclined', 'true'); + + this.showNotificationError('Push notifications timed out. This may be due to network restrictions. The app will work without push notifications.'); + } else { + this.showNotificationError('Failed to enable notifications. Please try again.'); + } } }); @@ -148,31 +158,13 @@ class AdminNotificationManager { } catch (error) { console.error('Failed to enable notifications:', error); - - // Show enhanced error message with diagnostics - let errorMessage = '❌ Failed to enable push notifications.\n\n'; - - if (error.message.includes('timed out') && error.message.includes('FCM')) { - errorMessage += '🔗 Network Issue Detected:\n'; - errorMessage += 'Your browser cannot connect to Chrome\'s push notification service (FCM). '; - errorMessage += 'This commonly happens with:\n'; - errorMessage += '• Corporate firewalls or VPNs\n'; - errorMessage += '• Network security software\n'; - errorMessage += '• Restricted internet connections\n\n'; - errorMessage += '💡 Workarounds:\n'; - errorMessage += '• Try from a different network\n'; - errorMessage += '• Disable VPN temporarily\n'; - errorMessage += '• Contact your IT department\n'; - errorMessage += '• Use a mobile hotspot to test\n\n'; - errorMessage += 'The admin panel will still work normally - you just won\'t receive push notifications.'; - } else { - errorMessage += `Error: ${error.message}`; - } - - this.showNotificationError(errorMessage); + // Re-throw so the caller can handle it + throw error; } finally { - button.disabled = false; - button.innerHTML = originalText; + if (button) { + button.disabled = false; + button.innerHTML = originalText; + } } }