diff --git a/apps.js b/apps.js index 99987c8..e4d699a 100644 --- a/apps.js +++ b/apps.js @@ -677,6 +677,65 @@ deletePlayerButton.addEventListener('click', () => { audioManager.play('modalClose'); }); +// Flic button action handler - Parse URL parameters and execute corresponding actions +function handleDeepLink() { + if (!window.location.hash) return; + + // Parse the hash to get action parameters + const params = new URLSearchParams(window.location.hash.substring(1)); + const action = params.get('action'); + + console.log('Received action from deep link:', action); + + // Execute action based on the parameter + switch (action) { + case 'start': + if (gameState === 'setup' || gameState === 'paused') { + if (players.length < 2) { + console.log('Cannot start: Need at least 2 players'); + return; + } + gameState = 'running'; + audioManager.play('gameStart'); + startTimer(); + updateGameButton(); + renderPlayers(); + saveData(); + } + break; + case 'pause': + if (gameState === 'running') { + gameState = 'paused'; + audioManager.play('gamePause'); + stopTimer(); + updateGameButton(); + renderPlayers(); + saveData(); + } + break; + case 'toggle': + // Toggle between start/pause depending on current state + gameButton.click(); + break; + case 'nextplayer': + if (gameState === 'running') { + const nextIndex = findNextPlayerWithTimeCircular(currentPlayerIndex, 1); + if (nextIndex !== -1 && nextIndex !== currentPlayerIndex) { + currentPlayerIndex = nextIndex; + audioManager.play('playerSwitch'); + renderPlayers(); + saveData(); + } + } + break; + default: + console.log('Unknown action:', action); + } + + // Clear the hash to prevent duplicate actions if page is refreshed + history.replaceState(null, null, ' '); +} + // Service Worker Registration if ('serviceWorker' in navigator) { window.addEventListener('load', () => { @@ -690,6 +749,12 @@ if ('serviceWorker' in navigator) { }); } +// Check for deep links when the page loads +window.addEventListener('load', handleDeepLink); + +// Also check for hash changes (needed for handling link activation when app is already open) +window.addEventListener('hashchange', handleDeepLink); + // Make sure to handle rotation by adding window event listener for orientation changes window.addEventListener('orientationchange', () => { // If camera is active, adjust video dimensions diff --git a/index.html b/index.html index 33c2d32..891ebbe 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,15 @@ + + + + + + + + +