mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 03:40:03 +01:00
Compare commits
16 Commits
dependabot
...
better-cac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d4e760572 | ||
|
|
e129e308a5 | ||
|
|
13e410d5bf | ||
|
|
503973ee12 | ||
|
|
c27690f3e4 | ||
|
|
6f0214339d | ||
|
|
fe5b438df6 | ||
|
|
2c127bc5f3 | ||
|
|
5ca84ae88a | ||
|
|
414f5aa7fb | ||
|
|
e3dfd1b5e5 | ||
|
|
1d9315d74a | ||
|
|
508d1d8f71 | ||
|
|
077d85bbb5 | ||
|
|
8580b07efb | ||
|
|
e4421c8bf5 |
@@ -256,3 +256,7 @@ a.name-header{
|
|||||||
align-content: center;
|
align-content: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#clear-cache {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,10 +17,33 @@ var setupCache = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
caches.keys().then(function(cacheNames) {
|
if (!('indexedDB' in window) || window.location.toString().includes('localhost') || window.location.toString().includes('127.0.0.1')) {
|
||||||
cacheNames.forEach(function(cacheName) {
|
console.log('No Cache Tracking');
|
||||||
$("#clear-cache").append(" " + cacheName);
|
caches.keys().then(function(cacheNames){
|
||||||
});
|
cacheNames.forEach(function(cacheName){
|
||||||
|
$('#clear-cache').append(" " + cacheName);
|
||||||
|
}
|
||||||
|
$('#clear-cache').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').text(`New Version Available ${out.version}`).fadeIn();
|
||||||
|
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 +59,4 @@ var setupCache = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = setupCache;
|
module.exports = setupCache;
|
||||||
|
|||||||
@@ -1,4 +1,29 @@
|
|||||||
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 = (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}`;
|
||||||
|
|
||||||
|
|
||||||
|
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 => {
|
self.addEventListener('install', event => {
|
||||||
console.log('Attempting to install service worker');
|
console.log('Attempting to install service worker');
|
||||||
@@ -10,9 +35,9 @@ self.addEventListener('activate', function(e) {
|
|||||||
caches.keys().then(function(cacheNames) {
|
caches.keys().then(function(cacheNames) {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
cacheNames.filter(function(cacheName){
|
cacheNames.filter(function(cacheName){
|
||||||
return cacheName.startsWith('image-sequencer-') &&
|
return isVersionNewer(staticCacheName.slice(-5), cacheName.slice(-5));
|
||||||
cacheName != staticCacheName;
|
|
||||||
}).map(function(cacheName){
|
}).map(function(cacheName){
|
||||||
|
|
||||||
return caches.delete(cacheName);
|
return caches.delete(cacheName);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -22,14 +47,40 @@ self.addEventListener('activate', function(e) {
|
|||||||
|
|
||||||
self.addEventListener('fetch', function(event) {
|
self.addEventListener('fetch', function(event) {
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
caches.open(staticCacheName).then(function(cache) {
|
if (caches.keys().length < 1){
|
||||||
return cache.match(event.request).then(function (response) {
|
caches.open(staticCacheName).then(function(cache) {
|
||||||
return response || fetch(event.request).then(function(response) {
|
return cache.match(event.request).then(function (response) {
|
||||||
if(event.request.method == "GET")
|
|
||||||
cache.put(event.request, response.clone());
|
return response || fetch(event.request).then(function(response) {
|
||||||
return response;
|
if(event.request.method == "GET")
|
||||||
|
cache.put(event.request, response.clone());
|
||||||
|
return response;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
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', {keyPath: 'name'});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,5 +17,9 @@
|
|||||||
"background_color": "#428bca",
|
"background_color": "#428bca",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"scope": "/examples/",
|
"scope": "/examples/",
|
||||||
"theme_color": "#428bca"
|
"theme_color": "#428bca",
|
||||||
}
|
"metadata": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"betaVersion": "3.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user