auto trigger game actions

This commit is contained in:
cpu
2025-03-29 05:38:10 +01:00
parent 72e1744a22
commit 2d8c1a6fff

View File

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