diff --git a/src/js/services/pushFlicIntegration.js b/src/js/services/pushFlicIntegration.js index ad1e84f..142c0c9 100644 --- a/src/js/services/pushFlicIntegration.js +++ b/src/js/services/pushFlicIntegration.js @@ -276,20 +276,18 @@ export function handleFlicAction(action, buttonId, timestamp, batteryLevel) { export function initPushFlic(handlers) { actionHandlers = handlers; // Store the handlers passed from app.js - // Don't auto-subscribe - wait for user action - // This prevents issues with permission/notification prompts appearing unexpectedly - + // Auto-subscribe when permission is granted if ('serviceWorker' in navigator) { navigator.serviceWorker.ready.then(registration => { - // Check if permission is already granted, but don't automatically subscribe - if (Notification.permission === 'granted') { - console.log('[PushFlic] Permission already granted, but waiting for user action to subscribe.'); - // Check if we have valid credentials - const hasCredentials = !!getBasicAuthCredentials(); - console.log('[PushFlic] Has stored credentials:', hasCredentials); - } else { - console.log('[PushFlic] Notification permission not granted yet.'); - } + Notification.requestPermission().then(permission => { + if (permission === 'granted') { + console.log('[PushFlic] Permission granted, attempting subscription.'); + subscribeToPush(); + } else { + console.log('[PushFlic] Notification permission not granted.'); + // Optionally provide a button for the user to trigger subscription later + } + }); }); } }