mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
update card layouts
This commit is contained in:
parent
614e07a81d
commit
cee7db2ce0
29 changed files with 194 additions and 71 deletions
|
@ -0,0 +1,111 @@
|
|||
var staticFileCacheName = 'staticfiles';
|
||||
var staticFileList;
|
||||
|
||||
var baseUrl = self.location.toString().substring(0, self.location.toString().lastIndexOf('/'));
|
||||
var staticFileBaseUrl = baseUrl + '/staticfiles';
|
||||
|
||||
console.log('service worker location: ' + self.location);
|
||||
console.log('service worker base url: ' + baseUrl);
|
||||
|
||||
function getStaticFileList() {
|
||||
|
||||
if (staticFileList) {
|
||||
return Promise.resolve(staticFileList);
|
||||
}
|
||||
|
||||
return fetch('staticfiles').then(function (response) {
|
||||
return response.json().then(function (list) {
|
||||
staticFileList = list;
|
||||
return list;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
self.addEventListener('install', function (event) {
|
||||
event.waitUntil(
|
||||
caches.open(staticFileCacheName).then(function (cache) {
|
||||
return getStaticFileList().then(function (files) {
|
||||
return cache.addAll(files);
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
function isCacheable(request) {
|
||||
|
||||
if ((request.method || '').toUpperCase() !== 'GET') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var url = request.url || '';
|
||||
|
||||
if (url.indexOf(baseUrl) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (url.indexOf(staticFileBaseUrl) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//self.addEventListener('fetch', function (event) {
|
||||
|
||||
// if (!isCacheable(event.request)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// event.respondWith(
|
||||
// caches.open(staticFileCacheName).then(function (cache) {
|
||||
// return cache.match(event.request).then(function (response) {
|
||||
// return response || fetch(event.request).then(function (response) {
|
||||
// cache.put(event.request, response.clone());
|
||||
// return response;
|
||||
// });
|
||||
// });
|
||||
// })
|
||||
// );
|
||||
//});
|
||||
|
||||
self.addEventListener('activate', function (event) {
|
||||
|
||||
event.waitUntil(
|
||||
caches.open(staticFileCacheName).then(function (cache) {
|
||||
return getStaticFileList().then(function (staticFiles) {
|
||||
|
||||
var setOfExpectedUrls = new Set(staticFiles);
|
||||
|
||||
return cache.keys().then(function (existingRequests) {
|
||||
|
||||
var existingBaseUrl = baseUrl + '/';
|
||||
|
||||
return Promise.all(
|
||||
existingRequests.map(function (existingRequest) {
|
||||
if (!setOfExpectedUrls.has(existingRequest.url.replace(existingBaseUrl, ''))) {
|
||||
|
||||
console.log('deleting cached file: ' + existingRequest.url);
|
||||
return cache.delete(existingRequest);
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
}).then(function () {
|
||||
return self.clients.claim();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('notificationclick', function (event) {
|
||||
event.notification.close();
|
||||
|
||||
var action = event.action;
|
||||
|
||||
if (action.indexOf('cancel-install') == 0) {
|
||||
var id = action.split('-')[2];
|
||||
console.log('cancel: ' + id);
|
||||
} else {
|
||||
clients.openWindow("/index.html");
|
||||
}
|
||||
}, false);
|
Loading…
Add table
Add a link
Reference in a new issue