|
|
@ -77,7 +77,8 @@ export class ApiManagerProxy extends CryptoWorkerMethods { |
|
|
|
private registerServiceWorker() { |
|
|
|
private registerServiceWorker() { |
|
|
|
if(!('serviceWorker' in navigator)) return; |
|
|
|
if(!('serviceWorker' in navigator)) return; |
|
|
|
|
|
|
|
|
|
|
|
navigator.serviceWorker.register('./sw.js', {scope: './'}).then(registration => { |
|
|
|
const worker = navigator.serviceWorker; |
|
|
|
|
|
|
|
worker.register('./sw.js', {scope: './'}).then(registration => { |
|
|
|
this.log('SW registered', registration); |
|
|
|
this.log('SW registered', registration); |
|
|
|
this.isSWRegistered = true; |
|
|
|
this.isSWRegistered = true; |
|
|
|
|
|
|
|
|
|
|
@ -86,33 +87,29 @@ export class ApiManagerProxy extends CryptoWorkerMethods { |
|
|
|
this.log('SW statechange', e); |
|
|
|
this.log('SW statechange', e); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const controller = navigator.serviceWorker.controller || registration.installing || registration.waiting || registration.active; |
|
|
|
/// #if MTPROTO_SW
|
|
|
|
|
|
|
|
const controller = worker.controller || registration.installing || registration.waiting || registration.active; |
|
|
|
this.onWorkerFirstMessage(controller); |
|
|
|
this.onWorkerFirstMessage(controller); |
|
|
|
|
|
|
|
/// #endif
|
|
|
|
}, (err) => { |
|
|
|
}, (err) => { |
|
|
|
this.isSWRegistered = false; |
|
|
|
this.isSWRegistered = false; |
|
|
|
this.log.error('SW registration failed!', err); |
|
|
|
this.log.error('SW registration failed!', err); |
|
|
|
appDocsManager.onServiceWorkerFail(); |
|
|
|
appDocsManager.onServiceWorkerFail(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/* navigator.serviceWorker.ready.then((registration) => { |
|
|
|
worker.addEventListener('controllerchange', () => { |
|
|
|
this.log('set SW', navigator.serviceWorker); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//registration.update();
|
|
|
|
|
|
|
|
}); */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
navigator.serviceWorker.addEventListener('controllerchange', () => { |
|
|
|
|
|
|
|
this.log.warn('controllerchange'); |
|
|
|
this.log.warn('controllerchange'); |
|
|
|
this.releasePending(); |
|
|
|
this.releasePending(); |
|
|
|
|
|
|
|
|
|
|
|
navigator.serviceWorker.controller.addEventListener('error', (e) => { |
|
|
|
worker.controller.addEventListener('error', (e) => { |
|
|
|
this.log.error('controller error:', e); |
|
|
|
this.log.error('controller error:', e); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/// #if MTPROTO_SW
|
|
|
|
/// #if MTPROTO_SW
|
|
|
|
navigator.serviceWorker.addEventListener('message', this.onWorkerMessage); |
|
|
|
worker.addEventListener('message', this.onWorkerMessage); |
|
|
|
/// #else
|
|
|
|
/// #else
|
|
|
|
navigator.serviceWorker.addEventListener('message', (e) => { |
|
|
|
worker.addEventListener('message', (e) => { |
|
|
|
const task: ServiceWorkerTask = e.data; |
|
|
|
const task: ServiceWorkerTask = e.data; |
|
|
|
if(!isObject(task)) { |
|
|
|
if(!isObject(task)) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -122,7 +119,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods { |
|
|
|
}); |
|
|
|
}); |
|
|
|
/// #endif
|
|
|
|
/// #endif
|
|
|
|
|
|
|
|
|
|
|
|
navigator.serviceWorker.addEventListener('messageerror', (e) => { |
|
|
|
worker.addEventListener('messageerror', (e) => { |
|
|
|
this.log.error('SW messageerror:', e); |
|
|
|
this.log.error('SW messageerror:', e); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|