URI: 
       perhaps bonghits will fix my service worker - webgbcam - [fork] gameboy webcam
  HTML git clone git://src.adamsgaard.dk/webgbcam
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit bd67cb8f7d43ab322642e3af9b4ba89b2a9de74f
   DIR parent 7cc1690613ae332ba9a722ab25d9d1e4b5e1d0a8
  HTML Author: Erin Pinheiro <erin.manal@gmail.com>
       Date:   Wed, 24 May 2023 22:27:03 +0100
       
       perhaps bonghits will fix my service worker
       
       Diffstat:
         M index.html                          |       2 +-
         M sw.js                               |     106 +++++++++++++++----------------
       
       2 files changed, 53 insertions(+), 55 deletions(-)
       ---
   DIR diff --git a/index.html b/index.html
       @@ -15,7 +15,7 @@
        </head>
        <body>
                <div class="maple-window">
       -                <div class="maple-window-title"><span>webgbcam v4.0</span></div>
       +                <div class="maple-window-title"><span>webgbcam v4.1</span></div>
                        <div id="camera">
                                <canvas id="app-view"></canvas>
                                <canvas id="camera-view"></canvas>
   DIR diff --git a/sw.js b/sw.js
       @@ -1,64 +1,62 @@
       -const cacheName = 'webgbcam-v4.0'
       +const cacheName = 'webgbcam-v4.1'
        
       -self.addEventListener('install', function(e) {
       -e.waitUntil(
       -        caches.open(cacheName).then(function(cache) {
       +// Install a service worker
       +self.addEventListener("install", (event) => {
       +  // Perform install steps
       +  caches.open(cacheName).then(function(cache) {
                        return cache.addAll([
       -                        '.',
       -                        'index.html',
       -                        'style.css',
       -                        'app.js',
       -                        'ui/bg.png',
       -                        'ui/mac-frame.png',
       -                        'ui/ui-capture.png',
       -                        'ui/ui-settings.png',
       -                        'ui/ui-main.png',
       -                        'ui/ui-hidden.png',
       -                        'ui/ui-timer.png',
       -                        'ui/ui-record.png',
       -                        'ui/loading.gif',
       -                        'gifjs/gif.js',
       -                        'gifjs/gif.worker.js'
       +                        '/',
       +                        '/index.html',
       +                        '/style.css',
       +                        '/app.js',
       +                        '/ui/bg.png',
       +                        '/ui/mac-frame.png',
       +                        '/ui/ui-capture.png',
       +                        '/ui/ui-settings.png',
       +                        '/ui/ui-main.png',
       +                        '/ui/ui-hidden.png',
       +                        '/ui/ui-timer.png',
       +                        '/ui/ui-record.png',
       +                        '/ui/loading.gif',
       +                        '/gifjs/gif.js',
       +                        '/gifjs/gif.worker.js'
                        ]);
       -        })
       -);
       +        });
        });
        
       -self.addEventListener('activate', function(event) {
       -        event.waitUntil(
       -                caches.keys().then(function(keyList) {
       -      return Promise.all(keyList.map(function(key) {
       -        if (key != cacheName) {
       -          return caches.delete(key);
       +// Cache lookup and fetch the request
       +self.addEventListener("fetch", (event) => {
       +  event.respondWith(
       +    caches.match(event.request).then(function (response) {
       +      // Cache hit - return response
       +      if (response) {
       +        return response;
       +      }
       +      return fetch(event.request).then(function (response) {
       +        if (!response || response.status !== 200 || response.type !== "basic") {
       +          return response;
                }
       -      }));
       -                })
       -        ).then(function () {
       -                return self.clients.claim();
       -        });
       +
       +        //Clone the response before putting into cache so that response to browser and response to cache happens in two difference streams
       +        var responseForCache = response.clone();
       +        caches.open(cacheName).then(function (cache) {
       +          cache.put(event.request, responseForCache);
       +        });
       +        return response;
       +      });
       +    })
       +  );
        });
        
       -// The fetch handler serves responses for same-origin resources from a cache.
       -// If no response is found, it populates the runtime cache with the response
       -// from the network before returning it to the page.
       -self.addEventListener('fetch', event => {
       -        // Skip cross-origin requests, like those for Google Analytics.
       -        if (event.request.url.startsWith(self.location.origin)) {
       -                event.respondWith(
       -                        caches.match(event.request).then(cachedResponse => {
       -                                if (cachedResponse) {
       -                                        return cachedResponse;
       +// Update a service worker
       +self.addEventListener("activate", (event) => {
       +  event.waitUntil(
       +    caches.keys().then(function(keyList) {
       +                        return Promise.all(keyList.map(function(key) {
       +                                if (key != cacheName) {
       +                                        return caches.delete(key);
                                        }
       -
       -                                return caches.open(cacheName).then(cache => {
       -                                        return fetch(event.request).then(response => {
       -                                                // Put a copy of the response in the runtime cache.
       -                                                return cache.put(event.request, response.clone()).then(() => {
       -                                                        return response;
       -                                                });
       -                                        });
       -                                });
       -                        })
       -                );
       -        }
       +                        }));
       +                })
       +  );
        });
        \ No newline at end of file