diff --git a/app.js b/app.js index 2041b67..6d7038c 100644 --- a/app.js +++ b/app.js @@ -5,7 +5,6 @@ import * as ui from './ui.js'; import * as timer from './timer.js'; import camera from './camera.js'; // Default export import audioManager from './audio.js'; -import deepLinkManager from './deeplinks.js'; import * as pushFlic from './pushFlicIntegration.js'; // --- Core Game Actions --- @@ -338,15 +337,9 @@ function setupServiceWorker() { // Initialize Flic integration (which will try to subscribe) initFlic(); - - // Setup deep links *after* SW might be ready - setupDeepLinks(); }) .catch(error => { console.error('ServiceWorker registration failed:', error); - // Still setup deep links even if SW fails - setupDeepLinks(); - // Maybe inform user push notifications won't work }); }); // Listen for SW controller changes @@ -357,40 +350,15 @@ function setupServiceWorker() { } else { console.warn('ServiceWorker not supported.'); - // Setup deep links anyway - window.addEventListener('load', setupDeepLinks); } } function handleServiceWorkerMessage(event) { - console.log('[App] Message received from Service Worker:', event.data); + console.log('[App] Message received from Service Worker:', event.data); if (event.data?.type === 'flic-action') { const { action, button, timestamp } = event.data; pushFlic.handleFlicAction(action, button, timestamp); } - else if (event.data?.type === 'ACTION') { // Handle deep link actions sent from SW - console.log('Received action from service worker via postMessage:', event.data.action); - deepLinkManager.handleAction(event.data.action); - } - // Add other message type handlers if needed -} - -// --- Deep Link Setup --- -function setupDeepLinks() { - deepLinkManager.registerHandler('start', startGame); - deepLinkManager.registerHandler('pause', pauseGame); - deepLinkManager.registerHandler('toggle', togglePauseResume); - deepLinkManager.registerHandler('nextplayer', nextPlayer); - deepLinkManager.registerHandler('prevplayer', previousPlayer); // Add previous player handler - deepLinkManager.registerHandler('reset', handleResetButtonClick); // Show confirmation - - // Process initial deep link on load - deepLinkManager.processDeepLink(); - - // Listen for subsequent deep links - window.addEventListener('hashchange', deepLinkManager.processDeepLink); - // Also listen for popstate if using history API or query params - window.addEventListener('popstate', deepLinkManager.processDeepLink); } // --- Flic Integration Setup --- @@ -453,7 +421,7 @@ function initialize() { ui.elements.resetCancelButton.addEventListener('click', handleResetCancel); ui.elements.cameraButton.addEventListener('click', handleCameraButtonClick); - // 6. Setup Service Worker (which also initializes Flic and Deep Links) + // 6. Setup Service Worker (which also initializes Flic) setupServiceWorker(); // 7. Initial UI Update based on loaded state diff --git a/deeplinks.js b/deeplinks.js deleted file mode 100644 index 374f0f6..0000000 --- a/deeplinks.js +++ /dev/null @@ -1,135 +0,0 @@ -// deeplinks.js - Deep Link Manager for Game Timer - -// Available actions -const VALID_ACTIONS = ['start', 'pause', 'toggle', 'nextplayer', 'reset']; - -// Class to manage all deep link functionality -class DeepLinkManager { - constructor() { - this.actionHandlers = {}; - - // Initialize listeners - this.initServiceWorkerListener(); - this.initHashChangeListener(); - this.initPopStateListener(); - } - - // Register action handlers - registerHandler(action, handlerFn) { - if (VALID_ACTIONS.includes(action)) { - this.actionHandlers[action] = handlerFn; - console.log(`Registered handler for action: ${action}`); - } else { - console.warn(`Attempted to register handler for invalid action: ${action}`); - } - } - - // Extract action from URL parameters (search or hash) - getActionFromUrl() { - // Check for action in both search params and hash - const searchParams = new URLSearchParams(window.location.search); - const hashParams = new URLSearchParams(window.location.hash.substring(1)); - - // First check search params (for direct curl or navigation) - const searchAction = searchParams.get('action'); - if (searchAction && VALID_ACTIONS.includes(searchAction)) { - console.log('Found action in search params:', searchAction); - return searchAction; - } - - // Then check hash params (existing deep link mechanism) - const hashAction = hashParams.get('action'); - if (hashAction && VALID_ACTIONS.includes(hashAction)) { - console.log('Found action in hash params:', hashAction); - return hashAction; - } - - return null; - } - - // Process an action - handleAction(action) { - if (!action) return; - - console.log('Processing action:', action); - - if (this.actionHandlers[action]) { - this.actionHandlers[action](); - } else { - console.log('No handler registered for action:', action); - } - } - - // Handle deep links from URL - processDeepLink() { - // Get action from URL parameters - const action = this.getActionFromUrl(); - - // Process the action if found - if (action) { - this.handleAction(action); - - // Clear the parameters to prevent duplicate actions if page is refreshed - if (window.history && window.history.replaceState) { - // Create new URL without the action parameter - const newUrl = window.location.pathname; - window.history.replaceState({}, document.title, newUrl); - } - } - } - - // Initialize service worker message listener - initServiceWorkerListener() { - if ('serviceWorker' in navigator) { - navigator.serviceWorker.addEventListener('message', (event) => { - if (event.data && event.data.type === 'ACTION') { - console.log('Received action from service worker:', event.data.action); - this.handleAction(event.data.action); - } - }); - } - } - - // Initialize hash change listener - initHashChangeListener() { - window.addEventListener('hashchange', () => { - console.log('Hash changed, checking for actions'); - this.processDeepLink(); - }); - } - - // Initialize popstate listener for navigation events - initPopStateListener() { - window.addEventListener('popstate', () => { - console.log('Navigation occurred, checking for actions'); - this.processDeepLink(); - }); - } - - // Send an action to the service worker - sendActionToServiceWorker(action) { - if ('serviceWorker' in navigator && navigator.serviceWorker.controller) { - navigator.serviceWorker.controller.postMessage({ - type: 'PROCESS_ACTION', - action: action - }); - } - } - - // Generate a deep link URL for a specific action - generateDeepLink(action, useHash = false) { - if (!VALID_ACTIONS.includes(action)) { - console.warn(`Cannot generate deep link for invalid action: ${action}`); - return null; - } - - const baseUrl = window.location.origin + window.location.pathname; - return useHash ? - `${baseUrl}#action=${action}` : - `${baseUrl}?action=${action}`; - } -} - -// Export singleton instance -const deepLinkManager = new DeepLinkManager(); -export default deepLinkManager; \ No newline at end of file diff --git a/index.html b/index.html index 42687e0..4407f35 100644 --- a/index.html +++ b/index.html @@ -9,14 +9,6 @@ - - - - - - - -