service-worker status indicator works well again (ref. #16)

merge-requests/4/merge
Michał 'rysiek' Woźniak 2021-09-19 11:56:57 +00:00
rodzic 05eea78700
commit c2451ba49e
1 zmienionych plików z 17 dodań i 17 usunięć

Wyświetl plik

@ -472,23 +472,6 @@ libresilient.displayMessage = (msg) => {
*/
window.addEventListener('load', function() {
libresilient.status = "loaded";
/*
* status display: how did this file get fetched?
*
* yes, this code has to be directly here,
* since we want to know how *this exact file* got fetched
*/
if (typeof libresilient.info[window.location.href] === 'object') {
// service worker info
for (let libresilient_sw of document.querySelectorAll(".libresilient-status-service-worker")) {
libresilient_sw.className += " active";
try {
libresilient_sw.querySelector('.status').innerHTML = "yes";
} catch(e) {
// nothing to do here, move along
}
}
}
// was any content unavailable so far?
if (libresilient.contentUnavailable) {
libresilient.displayMessage('Some content seems unavailable. Attempting to retrieve it via LibResilient.')
@ -527,6 +510,7 @@ if ('serviceWorker' in navigator) {
// handling the messages from ServiceWorker
navigator.serviceWorker.addEventListener('message', event => {
self.log('browser-side', 'LibResilientInfo received!')
if (event.data.url) {
self.log('browser-side', '+-- for:', event.data.url)
@ -595,7 +579,23 @@ if ('serviceWorker' in navigator) {
}
}
if (event.data.clientId) {
self.log('browser-side', '+-- got our clientId:', event.data.clientId)
// if libresilient.clientId is null, this is the first time
// we got wind that the service worker is running
// service worker info
if (libresilient.clientId === null) {
for (let libresilient_sw of document.querySelectorAll(".libresilient-status-service-worker")) {
libresilient_sw.className += " active";
try {
libresilient_sw.querySelector('.status').innerHTML = "yes";
} catch(e) {
// nothing to do here, move along
}
}
}
// set the clientId internally, we will need it
libresilient.clientId = event.data.clientId
}
if (event.data.plugins) {