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

View File

@@ -8,6 +8,15 @@
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<link rel="stylesheet" href="styles.css">
<!-- Deep Linking - App Links for Android -->
<link rel="alternate" href="android-app://eu.virtonline.gametimer/https://game-timer.virtonline.eu" />
<!-- Deep Linking - Universal Links for iOS -->
<meta name="apple-itunes-app" content="app-id=yourAppID, app-argument=https://game-timer.virtonline.eu">
<!-- Deep Linking - Web App URL Handling -->
<link rel="alternate" href="web+gametimer://action" />
</head>
<body>
<div class="app-container">
@@ -87,7 +96,8 @@
</div>
</div>
</div>
<!-- Camera Capture UI -->
<div id="cameraContainer" class="camera-container">
<div class="camera-view">
<video id="cameraView" autoplay playsinline></video>
@@ -98,7 +108,54 @@
<button id="cameraCaptureButton" class="camera-button-large"></button>
</div>
</div>
<!-- Script for handling URL scheme and deep links -->
<script type="module">
// Register the custom URL protocol handler (web+gametimer://)
if ('registerProtocolHandler' in navigator) {
try {
navigator.registerProtocolHandler(
'web+gametimer',
'https://game-timer.virtonline.eu/?action=%s',
'Game Timer'
);
console.log('Protocol handler registered');
} catch (e) {
console.error('Failed to register protocol handler:', e);
}
}
// Function to parse URL parameters
function getUrlParams() {
const searchParams = new URLSearchParams(window.location.search);
const hashParams = new URLSearchParams(window.location.hash.substring(1));
// Check search parameters first (for direct links)
const action = searchParams.get('action');
if (action) {
// Clean the action parameter (remove 'web+gametimer://' if present)
return action.replace('web+gametimer://', '');
}
// Then check hash parameters (for deep links)
return hashParams.get('action');
}
// Initialize URL handling
function initUrlHandling() {
const action = getUrlParams();
if (action) {
console.log('URL action detected:', action);
// Set the action in the hash to be processed by the main app
window.location.hash = `action=${action}`;
}
}
// Run initialization when DOM is fully loaded
document.addEventListener('DOMContentLoaded', initUrlHandling);
</script>
<!-- Main application script -->
<script type="module" src="audio.js"></script>
<script type="module" src="apps.js"></script>
<script>
@@ -107,12 +164,12 @@
.then(() => console.log("Service Worker Registered"))
.catch((err) => console.log("Service Worker Failed", err));
}
</script>
</script>
<footer class="app-footer">
<div class="author-info">
<p>Vibe coded by Martin</p>
<p>Version 0.0.1</p>
</div>
</footer>
</footer>
</body>
</html>