diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 6b26771..2cc0eca 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -122,35 +122,35 @@ class AdminPanelProvider extends PanelProvider // } - public function boot(): void - { - FilamentView::registerRenderHook('panels::head.end', function () { - // Only inject on the "home" page (or specific route) - if (url()->current() == config('app.url') . '/admin') { - return ' - - - - '; - } + // public function boot(): void + // { + // FilamentView::registerRenderHook('panels::head.end', function () { + // // Only inject on the "home" page (or specific route) + // if (url()->current() == config('app.url') . '/admin') { + // return ' + // + // + // + // '; + // } - return ''; // Do not inject on other pages - }); + // return ''; // Do not inject on other pages + // }); - // Only include PWA install script if on home page - FilamentView::registerRenderHook('panels::body.end', function () { - if (url()->current() == config('app.url') . '/admin') { - return ''; - } - return ''; - }); - } + // // Only include PWA install script if on home page + // FilamentView::registerRenderHook('panels::body.end', function () { + // if (url()->current() == config('app.url') . '/admin') { + // return ''; + // } + // return ''; + // }); + // } diff --git a/public/js/pwa-init.js b/public/js/pwa-init.js new file mode 100644 index 0000000..70530c5 --- /dev/null +++ b/public/js/pwa-init.js @@ -0,0 +1,26 @@ +(function() { + // Function to check if app is installed + function isPWAInstalled() { + return (window.matchMedia('(display-mode: standalone)').matches) + || (window.navigator.standalone === true); + } + + // Only run if PWA not installed and not injected yet + if (!isPWAInstalled() && !localStorage.getItem('pwaInjected')) { + // Dynamically inject manifest + const link = document.createElement('link'); + link.rel = 'manifest'; + link.href = '/manifest.json'; + document.head.appendChild(link); + + // Register Service Worker + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/sw.js') + .then(reg => console.log('Service Worker registered:', reg.scope)) + .catch(err => console.error('SW registration failed:', err)); + } + + // Mark as injected to prevent running again + localStorage.setItem('pwaInjected', 'true'); + } +})(); diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 27a1079..7e88e46 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -111,5 +111,11 @@ --}} + + + @include('partials.pwa') + + + diff --git a/resources/views/partials/pwa.blade.php b/resources/views/partials/pwa.blade.php new file mode 100644 index 0000000..bf3ec9c --- /dev/null +++ b/resources/views/partials/pwa.blade.php @@ -0,0 +1,2 @@ +{{-- Only include PWA script once --}} +