Browse Source

Use lock task only from window

master
Eduard Kuzmenko 2 years ago
parent
commit
1fd19121c0
  1. 4
      .env
  2. 20
      src/lib/mtproto/superMessagePort.ts

4
.env

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
API_ID=1025907
API_HASH=452b0359b988148995f22ff0f4229750
VERSION=1.5.0
VERSION_FULL=1.5.0 (226)
BUILD=226
VERSION_FULL=1.5.0 (227)
BUILD=227

20
src/lib/mtproto/superMessagePort.ts

@ -139,15 +139,17 @@ export default class SuperMessagePort< @@ -139,15 +139,17 @@ export default class SuperMessagePort<
this.log = logger('MP' + (logSuffix ? '-' + logSuffix : ''));
this.debug = DEBUG;
if('locks' in navigator) {
const id = 'lock-' + Date.now() + (Math.random() * 0xFFFF | 0);
navigator.locks.request(id, () => new Promise(() => {}));
this.pushTask(this.createTask('lock', id));
} else if(typeof(window) !== 'undefined') {
window.addEventListener('beforeunload', () => {
const task = this.createTask('close', undefined);
this.postMessage(undefined, task);
});
if(typeof(window) !== 'undefined') {
if('locks' in navigator) {
const id = 'lock-' + Date.now() + (Math.random() * 0xFFFF | 0);
navigator.locks.request(id, () => new Promise(() => {}));
this.pushTask(this.createTask('lock', id));
} else {
window.addEventListener('beforeunload', () => {
const task = this.createTask('close', undefined);
this.postMessage(undefined, task);
});
}
}
this.processTaskMap = {

Loading…
Cancel
Save