added URL scheme/deep linking

This commit is contained in:
cpu
2025-03-24 00:43:55 +01:00
parent 8a6947f4ea
commit 2838df5e05
8 changed files with 1142 additions and 31 deletions

65
apps.js
View File

@@ -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