From 0316c9482c1cd87569aaf9954248b9ff7ce28eb1 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 25 Oct 2020 17:38:14 +0100 Subject: [PATCH] . --- .idea/workspace.xml | 33 +++++++++---------- js/webapp.js | 2 +- scripts/lib/netflix.php | 7 ++++ scripts/lib/scenes.php | 6 ++-- service-worker.js | 73 ++++++----------------------------------- 5 files changed, 36 insertions(+), 85 deletions(-) create mode 100644 scripts/lib/netflix.php diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2b6fd88..dfb5bbd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,13 +2,10 @@ - - + - - - + @@ -1287,15 +1284,15 @@ - + - - + + - + diff --git a/js/webapp.js b/js/webapp.js index b504b2e..f3d6047 100644 --- a/js/webapp.js +++ b/js/webapp.js @@ -34,6 +34,6 @@ function installapp() { if ('serviceWorker' in navigator) { window.addEventListener('load', function() { console.log('👍', 'navigator.serviceWorker is supported'); - navigator.serviceWorker.register('/service-worker.js.template'); + navigator.serviceWorker.register('/service-worker.js'); }); } diff --git a/scripts/lib/netflix.php b/scripts/lib/netflix.php new file mode 100644 index 0000000..4a937b2 --- /dev/null +++ b/scripts/lib/netflix.php @@ -0,0 +1,7 @@ + 'function', 'function' => 'wakeupPC', 'args' => ['avion']], ], 'bureau/l61/on' => [ - ['type' => 'domoticz', 'device' => '2074', 'command' => true], + ['type' => 'domoticz', 'device' => '2074', 'command' => true, 'priority' => true], ], 'bureau/l61/off' => [ - ['type' => 'domoticz', 'device' => '2074', 'command' => false], + ['type' => 'domoticz', 'device' => '2074', 'command' => false, 'priority' => true], ], 'bureau/lumineux' => [ ['type' => 'scene', 'scene' => 'bureau/l61/on'], @@ -738,7 +738,7 @@ function execScene($name, $fromUserAction = false, $transitionTime = null) } if ($action['type'] == 'hue') { - hueCommand($action,$transitionTime); + hueCommand($action, $transitionTime); } else if ($action['type'] == 'insteon') { insteonCommand($action['command']); } else if ($action['type'] == 'delay' || $action['type'] == 'scene') { diff --git a/service-worker.js b/service-worker.js index bea63d7..4ad1a6c 100644 --- a/service-worker.js +++ b/service-worker.js @@ -1,67 +1,14 @@ -const CACHE_NAME = 'mpwa-cache-v1'; -const urlsToCache = ['./', 'index.php']; - -// Listen for the install event, which fires when the service worker is installing -self.addEventListener('install', event => { - // Ensures the install event doesn't complete until after the cache promise resolves - // This is so we don't move on to other events until the critical initial cache is done - event.waitUntil( - // Open a named cache, then add all the specified URLs to it - caches.open(CACHE_NAME).then(cache => cache.addAll(urlsToCache)) - ); +self.addEventListener('install', (event) => { + console.log('👷', 'install', event); + self.skipWaiting(); }); -// Listen for the activate event, which is fired after installation -// Activate is when the service worker actually takes over from the previous -// version, which is a good time to clean up old caches -self.addEventListener('activate', event => { - console.log('Finally active. Ready to serve!'); - event.waitUntil( - // Get the keys of all the old caches - caches - .keys() - // Ensure we don't resolve until all the promises do (i.e. each key has been deleted) - .then(keys => - Promise.all( - keys - // Remove any cache that matches the current cache name - .filter(key => key !== CACHE_NAME) - // Map over the array of old cache names and delete them all - .map(key => caches.delete(key)) - ) - ) - ); +self.addEventListener('activate', (event) => { + console.log('👷', 'activate', event); + return self.clients.claim(); }); -// Listen for browser fetch events. These fire any time the browser tries to load -// any outside resources -self.addEventListener('fetch', function (event) { - // This lets us control the response - // We pass in a promise that resolves with a response object - event.respondWith( - // Check whether we have a matching response for this request in our cache - caches.match(event.request).then(response => { - // It's in the cache! Serve the response straight from there - if (response) { - console.log('Serving response from the cache'); - return response; - } - // If it's not in the cache we make a fetch request for the resource - return ( - fetch(event.request) - // Then we open our cache - .then(response => caches.open(CACHE_NAME)) - // Then we put the request into the cache, so we have it offline next time - .then(cache => { - // We have to clone the response as response streams can only be read once - // This way we can put one copy in the cache and return the other to the browser - cache.put(event.request, response.clone()); - return response; - }) - .catch(response => { - console.log('Fetch failed, sorry.'); - }) - ); - }) - ); -}); +// self.addEventListener('fetch', function(event) { +// // console.log('👷', 'fetch', event); +// event.respondWith(fetch(event.request)); +// }); \ No newline at end of file -- 2.39.5