add PWA meta tags and service worker registration
This commit is contained in:
@@ -21,7 +21,16 @@ setSecurityHeaders();
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png">
|
||||
<link rel="manifest" href="site.webmanifest">
|
||||
<link rel="icon" type="image/x-icon" href="img/favicon.ico">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
<meta name="theme-color" content="#FF0000">
|
||||
|
||||
<!-- PWA Meta Tags -->
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||||
<meta name="apple-mobile-web-app-title" content="kaubuntu.re">
|
||||
<meta name="application-name" content="kaubuntu.re">
|
||||
<meta name="msapplication-TileColor" content="#FF0000">
|
||||
<meta name="msapplication-config" content="browserconfig.xml">
|
||||
</head>
|
||||
<body>
|
||||
<?php include 'includes/sidebar.php'; ?>
|
||||
@@ -377,5 +386,66 @@ setSecurityHeaders();
|
||||
<script src="js/main.js"></script>
|
||||
<script src="js/mastodon-timeline.umd.js"></script>
|
||||
<script src="js/mastodon-config.php"></script>
|
||||
|
||||
<!-- PWA Service Worker -->
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', function() {
|
||||
navigator.serviceWorker.register('/sw.js')
|
||||
.then(function(registration) {
|
||||
console.log('Service Worker enregistré avec succès:', registration.scope);
|
||||
|
||||
// Écouter les mises à jour
|
||||
registration.addEventListener('updatefound', function() {
|
||||
const newWorker = registration.installing;
|
||||
newWorker.addEventListener('statechange', function() {
|
||||
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
|
||||
// Nouvelle version disponible
|
||||
console.log('Nouvelle version disponible');
|
||||
if (confirm('Une nouvelle version est disponible. Voulez-vous recharger la page ?')) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log('Échec de l\'enregistrement du Service Worker:', err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Gestion de l'installation PWA
|
||||
let deferredPrompt;
|
||||
const installButton = document.getElementById('install-pwa');
|
||||
|
||||
window.addEventListener('beforeinstallprompt', function(e) {
|
||||
e.preventDefault();
|
||||
deferredPrompt = e;
|
||||
|
||||
// Afficher le bouton d'installation s'il existe
|
||||
if (installButton) {
|
||||
installButton.style.display = 'block';
|
||||
installButton.addEventListener('click', function() {
|
||||
deferredPrompt.prompt();
|
||||
deferredPrompt.userChoice.then(function(choiceResult) {
|
||||
if (choiceResult.outcome === 'accepted') {
|
||||
console.log('PWA installée');
|
||||
}
|
||||
deferredPrompt = null;
|
||||
installButton.style.display = 'none';
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Masquer le bouton après installation
|
||||
window.addEventListener('appinstalled', function() {
|
||||
console.log('PWA installée avec succès');
|
||||
if (installButton) {
|
||||
installButton.style.display = 'none';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user