From 1fd19121c081d32f6e438554f8750b62f6dee14b Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Mon, 22 Aug 2022 13:15:27 +0200 Subject: [PATCH] Use lock task only from window --- .env | 4 ++-- src/lib/mtproto/superMessagePort.ts | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.env b/.env index f8ae5d16..7d2be8be 100644 --- a/.env +++ b/.env @@ -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 diff --git a/src/lib/mtproto/superMessagePort.ts b/src/lib/mtproto/superMessagePort.ts index 3fa1c605..efefef0b 100644 --- a/src/lib/mtproto/superMessagePort.ts +++ b/src/lib/mtproto/superMessagePort.ts @@ -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 = {