mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-09 04:06:27 -04:00
Prevent full disabling of Service Worker in PWA context
Former-commit-id: e1287fcc5fe2a70eac9e032b225c5d05e71ff601 [formerly 5b5fc90d2c9aca13adde71727766845179a1fb0e [formerly 64404cb1254695c9e824123186924c69a5fa1d0f]] Former-commit-id: b4a68c0ecc37d119d1686e18602c0297a136114a Former-commit-id: ff1da3af395b43d85cace4b967ff1d0f3192fede
This commit is contained in:
parent
dd30ec42ff
commit
7d1420257e
@ -1435,22 +1435,28 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
|
|||||||
function setContentInjectionMode(value) {
|
function setContentInjectionMode(value) {
|
||||||
params.contentInjectionMode = value;
|
params.contentInjectionMode = value;
|
||||||
if (value === 'jquery') {
|
if (value === 'jquery') {
|
||||||
if (isServiceWorkerReady()) {
|
// Because the "outer" Service Worker still runs in a PWA app, we don't actually disable the SW in this context, but it will no longer
|
||||||
// We need to disable the ServiceWorker
|
// be intercepting requests
|
||||||
// Unregistering it does not seem to work as expected : the ServiceWorker
|
if ('serviceWorker' in navigator && /\/\/(localhost|kiwix.github.io)\//i.test(window.location.href)) {
|
||||||
// is indeed unregistered but still active...
|
serviceWorkerRegistration = null;
|
||||||
// So we have to disable it manually (even if it's still registered and active)
|
} else {
|
||||||
navigator.serviceWorker.controller.postMessage({
|
if (isServiceWorkerReady()) {
|
||||||
'action': 'disable'
|
// We need to disable the ServiceWorker
|
||||||
});
|
// Unregistering it does not seem to work as expected : the ServiceWorker
|
||||||
messageChannel = null;
|
// is indeed unregistered but still active...
|
||||||
// If we're in electron or nwjs, completely remove the SW (but we need to keep it active if we're in a PWA)
|
// So we have to disable it manually (even if it's still registered and active)
|
||||||
if (typeof window.fs !== 'undefined') {
|
navigator.serviceWorker.controller.postMessage({
|
||||||
navigator.serviceWorker.getRegistrations().then(function (registrations) {
|
'action': 'disable'
|
||||||
registrations.forEach(function (registration) {
|
|
||||||
registration.unregister();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
messageChannel = null;
|
||||||
|
// If we're in electron, completely remove the SW (but we need to keep it active if we're in a PWA)
|
||||||
|
if (typeof window.fs !== 'undefined') {
|
||||||
|
navigator.serviceWorker.getRegistrations().then(function (registrations) {
|
||||||
|
registrations.forEach(function (registration) {
|
||||||
|
registration.unregister();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
refreshAPIStatus();
|
refreshAPIStatus();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user