diff --git a/app/js/main.js b/app/js/main.js index 160b06e..95869a2 100644 --- a/app/js/main.js +++ b/app/js/main.js @@ -8,25 +8,48 @@ * @link https://TheTempusProject.com * @license https://opensource.org/licenses/MIT [MIT LICENSE] */ +/** + * Progressive Web-App + **/ let deferredPrompt; const installPrompt = document.getElementById("install-prompt"); +const chromeMessage = document.getElementById("chrome-install-message"); +const iosMessage = document.getElementById("ios-install-message"); const installButton = document.getElementById("install-button"); const dismissButton = document.querySelector("#install-prompt .btn-close"); // Check if the user previously dismissed the prompt -if (!localStorage.getItem("pwaInstallDismissed")) { +if ( ! localStorage.getItem("pwaInstallDismissed") ) { window.addEventListener("beforeinstallprompt", (event) => { event.preventDefault(); deferredPrompt = event; installPrompt.classList.remove("d-none"); - installPrompt.classList.add("d-block"); // Show the prompt + installPrompt.classList.add("d-block"); // Show the alert + chromeMessage.classList.remove("d-none"); + chromeMessage.classList.add("d-block"); // Show the prompt }); + + if ( isIos() && ! isInStandaloneMode() ) { + installPrompt.classList.remove("d-none"); + installPrompt.classList.add("d-block"); // Show the alert + iosMessage.classList.remove("d-none"); + iosMessage.classList.add("d-block"); // Show the prompt + } } +// ios REQUIRES a service worker +if ( 'serviceWorker' in navigator ) { + navigator.serviceWorker.register('app/js/sw.js') + .then(() => console.log('Service Worker Registered')); +} +// self.addEventListener('install', () => self.skipWaiting()); +// self.addEventListener('activate', () => self.clients.claim()); +// self.addEventListener('fetch', () => {}); // No file interception + // Handle Install Button Click if ( installButton ) { installButton.addEventListener("click", async () => { - if (deferredPrompt) { + if ( deferredPrompt ) { deferredPrompt.prompt(); const { outcome } = await deferredPrompt.userChoice; @@ -65,6 +88,14 @@ if (localStorage.getItem("pwaInstallDismissed")) { } } +function isIos() { + return /iphone|ipad|ipod/i.test(navigator.userAgent); +} + +function isInStandaloneMode() { + return window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone; +} + /** * Automatically selects/de-selects all check boxes associated with that field **/ diff --git a/app/js/sw.js b/app/js/sw.js new file mode 100644 index 0000000..89c3448 --- /dev/null +++ b/app/js/sw.js @@ -0,0 +1 @@ +self.addEventListener('fetch', () => {}); \ No newline at end of file diff --git a/app/models/sessions.php b/app/models/sessions.php index 2070dde..df5f2b2 100644 --- a/app/models/sessions.php +++ b/app/models/sessions.php @@ -59,7 +59,7 @@ class Sessions extends DatabaseModel { public function checkSession( $sessionID ) { $user = new User; // @todo lets put this on some sort of realistic checking regime other than check everything every time - if ( $sessionID == false ) { + if ( empty( $sessionID ) ) { Debug::log( 'sessionID false' ); return false; } diff --git a/app/templates/default/default.tpl b/app/templates/default/default.tpl index 0e9aa7a..24e5a02 100644 --- a/app/templates/default/default.tpl +++ b/app/templates/default/default.tpl @@ -28,7 +28,12 @@ {AUTHOR} {ROBOT} + + + + + diff --git a/app/views/faq.html b/app/views/faq.html index 956f2b6..b914758 100644 --- a/app/views/faq.html +++ b/app/views/faq.html @@ -56,8 +56,8 @@