From 68ef919c668debf560dc242b502f2e630a01b9c1 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Thu, 27 Jul 2023 11:48:31 +0200 Subject: [PATCH] Lock Screen: Fix hanging log out (#3672) --- src/api/gramjs/methods/client.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/api/gramjs/methods/client.ts b/src/api/gramjs/methods/client.ts index 306442880..3cbd6b5bf 100644 --- a/src/api/gramjs/methods/client.ts +++ b/src/api/gramjs/methods/client.ts @@ -37,6 +37,7 @@ import { reset as resetUpdatesManager, scheduleGetChannelDifference, } from '../updateManager'; +import { pause } from '../../../util/schedulers'; const DEFAULT_USER_AGENT = 'Unknown UserAgent'; const DEFAULT_PLATFORM = 'Unknown platform'; @@ -163,9 +164,13 @@ export function setIsPremium({ isPremium }: { isPremium: boolean }) { client.setIsPremium(isPremium); } +const LOG_OUT_TIMEOUT = 2500; export async function destroy(noLogOut = false, noClearLocalDb = false) { - if (!noLogOut) { - await invokeRequest(new GramJs.auth.LogOut()); + if (!noLogOut && client.isConnected()) { + await Promise.race([ + invokeRequest(new GramJs.auth.LogOut()), + pause(LOG_OUT_TIMEOUT), + ]); } if (!noClearLocalDb) {