From e4421c8bf5f4f2d09837870eb5dfdfa931028f47 Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 17:32:53 +0000 Subject: [PATCH 01/16] Update manifest.json --- examples/manifest.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/manifest.json b/examples/manifest.json index d90fa4d357..b81910558c 100644 --- a/examples/manifest.json +++ b/examples/manifest.json @@ -17,5 +17,9 @@ "background_color": "#428bca", "display": "standalone", "scope": "/examples/", - "theme_color": "#428bca" -} \ No newline at end of file + "theme_color": "#428bca", + "metadata": { + "version": 3.0.0, + "beta-version":3.0.0 + } +} From 8580b07efb3efbc4092b7b437dbc68bc42316ff3 Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 17:34:11 +0000 Subject: [PATCH 02/16] Update manifest.json --- examples/manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/manifest.json b/examples/manifest.json index b81910558c..d0ebc76b5d 100644 --- a/examples/manifest.json +++ b/examples/manifest.json @@ -19,7 +19,7 @@ "scope": "/examples/", "theme_color": "#428bca", "metadata": { - "version": 3.0.0, - "beta-version":3.0.0 + "version": "3.0.0", + "beta-version": "3.0.0" } } From 077d85bbb53619008d945ee5b489319872aca288 Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 17:45:27 +0000 Subject: [PATCH 03/16] Update manifest.json --- examples/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/manifest.json b/examples/manifest.json index d0ebc76b5d..4b47c27a01 100644 --- a/examples/manifest.json +++ b/examples/manifest.json @@ -20,6 +20,6 @@ "theme_color": "#428bca", "metadata": { "version": "3.0.0", - "beta-version": "3.0.0" + "betaVersion": "3.0.0" } } From 508d1d8f71eb5fcee5b3affddbad7d2c03a325de Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 18:02:26 +0000 Subject: [PATCH 04/16] Update sw.js --- examples/lib/sw.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/lib/sw.js b/examples/lib/sw.js index c8c342c5a1..c9ccc8beae 100644 --- a/examples/lib/sw.js +++ b/examples/lib/sw.js @@ -1,4 +1,12 @@ -const staticCacheName = 'image-sequencer-static-v3'; +const request = new XMLHttpRequest(); +request.open("GET", "../manifest.json", false); +request.send(null); +const meta = JSON.parse(request.responseText).metadata, + ver = meta.version, + betaVer = meta.betaVersion; +const version = (window.location.indexOf('beta') == 0) ? betaVer : ver; + +const staticCacheName = `image-sequencer-static-v${version}`; self.addEventListener('install', event => { console.log('Attempting to install service worker'); @@ -32,4 +40,4 @@ self.addEventListener('fetch', function(event) { }); }) ); -}); \ No newline at end of file +}); From 1d9315d74ace26468526e5128031face050299fb Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 18:27:44 +0000 Subject: [PATCH 05/16] Update sw.js --- examples/lib/sw.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/examples/lib/sw.js b/examples/lib/sw.js index c9ccc8beae..2a57f1f190 100644 --- a/examples/lib/sw.js +++ b/examples/lib/sw.js @@ -8,6 +8,22 @@ const version = (window.location.indexOf('beta') == 0) ? betaVer : ver; const staticCacheName = `image-sequencer-static-v${version}`; +const isVersionNewer = (version, old) => { + version = version.split('.'); + var major = version[0], + minor = version[1], + patch = version[2]; + old = old.split('.'); + var oldMajor = old[0], + oldMinor = old[1], + oldPatch = old[2]; + + if (major > oldMajor) return true + else if (minor > oldMinor) return true + else if (patch > oldPatch) return true + else return false +} + self.addEventListener('install', event => { console.log('Attempting to install service worker'); }); @@ -18,8 +34,7 @@ self.addEventListener('activate', function(e) { caches.keys().then(function(cacheNames) { return Promise.all( cacheNames.filter(function(cacheName){ - return cacheName.startsWith('image-sequencer-') && - cacheName != staticCacheName; + cacheName != staticCacheName; }).map(function(cacheName){ return caches.delete(cacheName); }) From e3dfd1b5e5556ddb0e6316561c1eb26d3a4036ed Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 19:08:06 +0000 Subject: [PATCH 06/16] Update sw.js --- examples/lib/sw.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/examples/lib/sw.js b/examples/lib/sw.js index 2a57f1f190..b98dbbeca4 100644 --- a/examples/lib/sw.js +++ b/examples/lib/sw.js @@ -6,7 +6,8 @@ const meta = JSON.parse(request.responseText).metadata, betaVer = meta.betaVersion; const version = (window.location.indexOf('beta') == 0) ? betaVer : ver; -const staticCacheName = `image-sequencer-static-v${version}`; +const staticCacheName = `image-sequencer-static-v${version}`, + is const isVersionNewer = (version, old) => { version = version.split('.'); @@ -34,8 +35,9 @@ self.addEventListener('activate', function(e) { caches.keys().then(function(cacheNames) { return Promise.all( cacheNames.filter(function(cacheName){ - cacheName != staticCacheName; + return isVersionNewer(staticCacheName.slice(-5), cacheName.slice(-5)); }).map(function(cacheName){ + return caches.delete(cacheName); }) ); @@ -45,14 +47,18 @@ self.addEventListener('activate', function(e) { self.addEventListener('fetch', function(event) { event.respondWith( - caches.open(staticCacheName).then(function(cache) { - return cache.match(event.request).then(function (response) { - return response || fetch(event.request).then(function(response) { - if(event.request.method == "GET") - cache.put(event.request, response.clone()); - return response; + if (caches.keys().length < 1){ + caches.open(staticCacheName).then(function(cache) { + return cache.match(event.request).then(function (response) { + + return response || fetch(event.request).then(function(response) { + if(event.request.method == "GET") + cache.put(event.request, response.clone()); + return response; + }); }); }); - }) + } + else return false; ); }); From 414f5aa7fb875a69507ba83e92cd38b7b2179afd Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 19:37:57 +0000 Subject: [PATCH 07/16] Update sw.js --- examples/lib/sw.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/examples/lib/sw.js b/examples/lib/sw.js index b98dbbeca4..52f90759e2 100644 --- a/examples/lib/sw.js +++ b/examples/lib/sw.js @@ -58,6 +58,28 @@ self.addEventListener('fetch', function(event) { }); }); }); + if (!('indexedDB' in window)) { + console.log('This browser doesn\'t support IndexedDB'); + return; + } + + var dbPromise = idb.open('cache-db', 1, function(upgradeDb) { + if (!upgradeDb.objectStoreNames.contains('caches')) { + var cachedb = upgradeDb.createObjectStore('cache', {autoIncrement: true}); + cachedb.createIndex('version', 'version', {unique: false}); + } + } + dbPromise.then(function(db) { + var tx = db.transaction('caches', 'readwrite'); + var store = tx.objectStore('caches'); + var item = { + name: 'new-cache-availalble', + version: staticCacheName, + created: new Date().getTime() + }; + store.add(item); + return tx.complete; + }) } else return false; ); From 5ca84ae88aa64e7074dfda747c66d50bd8f0dc9e Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 19:43:08 +0000 Subject: [PATCH 08/16] Update sw.js --- examples/lib/sw.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/lib/sw.js b/examples/lib/sw.js index 52f90759e2..4c727a455f 100644 --- a/examples/lib/sw.js +++ b/examples/lib/sw.js @@ -65,8 +65,8 @@ self.addEventListener('fetch', function(event) { var dbPromise = idb.open('cache-db', 1, function(upgradeDb) { if (!upgradeDb.objectStoreNames.contains('caches')) { - var cachedb = upgradeDb.createObjectStore('cache', {autoIncrement: true}); - cachedb.createIndex('version', 'version', {unique: false}); + var cachedb = upgradeDb.createObjectStore('cache', {keyPath: }); + } } dbPromise.then(function(db) { From 2c127bc5f3ea157f694334c77c7b7c23d403bdcb Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 19:43:43 +0000 Subject: [PATCH 09/16] Update sw.js --- examples/lib/sw.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/lib/sw.js b/examples/lib/sw.js index 4c727a455f..922e4e3eae 100644 --- a/examples/lib/sw.js +++ b/examples/lib/sw.js @@ -65,7 +65,7 @@ self.addEventListener('fetch', function(event) { var dbPromise = idb.open('cache-db', 1, function(upgradeDb) { if (!upgradeDb.objectStoreNames.contains('caches')) { - var cachedb = upgradeDb.createObjectStore('cache', {keyPath: }); + var cachedb = upgradeDb.createObjectStore('cache', {keyPath: 'name'}); } } From fe5b438df6bfa5cc87065007e6c0e27d13495f9f Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 19:57:42 +0000 Subject: [PATCH 10/16] Update cache.js --- examples/lib/cache.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/examples/lib/cache.js b/examples/lib/cache.js index d1038f8c2e..1bd6bbdecd 100644 --- a/examples/lib/cache.js +++ b/examples/lib/cache.js @@ -17,10 +17,31 @@ var setupCache = function() { } if ('serviceWorker' in navigator) { - caches.keys().then(function(cacheNames) { - cacheNames.forEach(function(cacheName) { - $("#clear-cache").append(" " + cacheName); - }); + if (!('indexedDB' in window)) { + console.log('This browser doesn\'t support IndexedDB'); + caches.keys().forEach(function(cacheName){ + $('#clear-cache').append(" " + cacheName).fadeIn(); + + } + return; + } + var dbPromise = idb.open('cache-db', 1); + dbPromise.then(function(db) { + var tx = db.transaction('caches', 'readwrite'); + var store = tx.objectStore('caches'); + return store.get('new-cache-available'); + }).then(function(out) { + if (out == undefined) return; + else { + $('#clear-cache').append(`New Cache Available ${out.version}`); + var dbPromise = idb.open('cache-db', 1); + dbPromise.then(function(db) { + var tx = db.transaction('caches', 'readwrite'); + var store = tx.objectStore('caches'); + store.delete('new-cache-available'); + return tx.complete; + }); + } }); } @@ -36,4 +57,4 @@ var setupCache = function() { }); } -module.exports = setupCache; \ No newline at end of file +module.exports = setupCache; From 6f0214339d03273d48c09338c6cea079a0f4ebc0 Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 19:58:43 +0000 Subject: [PATCH 11/16] Update cache.js --- examples/lib/cache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/lib/cache.js b/examples/lib/cache.js index 1bd6bbdecd..e4ad14168a 100644 --- a/examples/lib/cache.js +++ b/examples/lib/cache.js @@ -33,7 +33,7 @@ var setupCache = function() { }).then(function(out) { if (out == undefined) return; else { - $('#clear-cache').append(`New Cache Available ${out.version}`); + $('#clear-cache').text(`New Version Available ${out.version}`).fadeIn(); var dbPromise = idb.open('cache-db', 1); dbPromise.then(function(db) { var tx = db.transaction('caches', 'readwrite'); From c27690f3e428d9160a89570e45f1c12c026f8296 Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 20:02:04 +0000 Subject: [PATCH 12/16] Update demo.css --- examples/demo.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/demo.css b/examples/demo.css index 2798012f6b..68a9d4f456 100644 --- a/examples/demo.css +++ b/examples/demo.css @@ -256,3 +256,7 @@ a.name-header{ align-content: center; justify-content: center; } + +#clear-cache { + display: none; +} From 503973ee123e889d7cb10ee825481f4bfe4c799f Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 20:04:47 +0000 Subject: [PATCH 13/16] Update cache.js --- examples/lib/cache.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/lib/cache.js b/examples/lib/cache.js index e4ad14168a..9a234a6db0 100644 --- a/examples/lib/cache.js +++ b/examples/lib/cache.js @@ -19,9 +19,11 @@ var setupCache = function() { if ('serviceWorker' in navigator) { if (!('indexedDB' in window)) { console.log('This browser doesn\'t support IndexedDB'); - caches.keys().forEach(function(cacheName){ - $('#clear-cache').append(" " + cacheName).fadeIn(); - + caches.keys().then(function(cacheNames){ + cacheNames.forEach(function(cacheName){ + $('#clear-cache').append(" " + cacheName); + } + $('#clear-cache').fadeIn(); } return; } From 13e410d5bf2310103006a3a52d9e1b1eda242b45 Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 20:17:40 +0000 Subject: [PATCH 14/16] Update sw.js --- examples/lib/sw.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/lib/sw.js b/examples/lib/sw.js index 922e4e3eae..b89bdfeca7 100644 --- a/examples/lib/sw.js +++ b/examples/lib/sw.js @@ -4,7 +4,7 @@ request.send(null); const meta = JSON.parse(request.responseText).metadata, ver = meta.version, betaVer = meta.betaVersion; -const version = (window.location.indexOf('beta') == 0) ? betaVer : ver; +const version = (self.location.toString().indexOf('beta') == 0 || self.location.toString().includes('localhost') || self.location.toString().includes('127.0.0.1')) ? betaVer : ver; const staticCacheName = `image-sequencer-static-v${version}`, is From e129e308a5e7cd2ae9e5a5ee2dab4d2776ccb2f9 Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 20:25:26 +0000 Subject: [PATCH 15/16] Update cache.js --- examples/lib/cache.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/lib/cache.js b/examples/lib/cache.js index 9a234a6db0..05203c0c04 100644 --- a/examples/lib/cache.js +++ b/examples/lib/cache.js @@ -17,8 +17,8 @@ var setupCache = function() { } if ('serviceWorker' in navigator) { - if (!('indexedDB' in window)) { - console.log('This browser doesn\'t support IndexedDB'); + if (!('indexedDB' in window) || window.location.toString().includes('localhost') || window.location.toString().includes('127.0.0.1')) { + console.log('No Cache Tracking'); caches.keys().then(function(cacheNames){ cacheNames.forEach(function(cacheName){ $('#clear-cache').append(" " + cacheName); From 0d4e7605721503a041d9c2925043bf6265a9838b Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Date: Wed, 27 Mar 2019 20:39:01 +0000 Subject: [PATCH 16/16] Update sw.js --- examples/lib/sw.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/lib/sw.js b/examples/lib/sw.js index b89bdfeca7..fbe6290b7f 100644 --- a/examples/lib/sw.js +++ b/examples/lib/sw.js @@ -6,8 +6,8 @@ const meta = JSON.parse(request.responseText).metadata, betaVer = meta.betaVersion; const version = (self.location.toString().indexOf('beta') == 0 || self.location.toString().includes('localhost') || self.location.toString().includes('127.0.0.1')) ? betaVer : ver; -const staticCacheName = `image-sequencer-static-v${version}`, - is +const staticCacheName = `image-sequencer-static-v${version}`; + const isVersionNewer = (version, old) => { version = version.split('.');