diff --git a/src/app/components/telegram-login/telegram-login.component.ts b/src/app/components/telegram-login/telegram-login.component.ts index 5b18957..2d6380b 100644 --- a/src/app/components/telegram-login/telegram-login.component.ts +++ b/src/app/components/telegram-login/telegram-login.component.ts @@ -23,15 +23,10 @@ export class TelegramLoginComponent implements OnDestroy { private readonly pollIntervalMs = 5000; private pollTimer?: ReturnType; - private mobileFallbackTimeout?: ReturnType; - private launchFrame?: HTMLIFrameElement; private readonly handleVisibilityChange = () => { - if (typeof document !== 'undefined' && document.visibilityState === 'hidden') { - this.clearMobileLaunchArtifacts(); - return; + if (typeof document !== 'undefined' && document.visibilityState === 'visible') { + this.checkLoginAfterReturn(); } - - this.checkLoginAfterReturn(); }; private readonly handleWindowFocus = () => { this.checkLoginAfterReturn(); @@ -46,7 +41,6 @@ export class TelegramLoginComponent implements OnDestroy { this.initQrLogin(); } else { this.awaitingTelegramReturn.set(false); - this.clearMobileLaunchArtifacts(); this.stopPolling(); } }); @@ -60,7 +54,6 @@ export class TelegramLoginComponent implements OnDestroy { ngOnDestroy(): void { this.awaitingTelegramReturn.set(false); - this.clearMobileLaunchArtifacts(); this.stopPolling(); if (typeof window !== 'undefined') { @@ -72,7 +65,6 @@ export class TelegramLoginComponent implements OnDestroy { close(): void { this.awaitingTelegramReturn.set(false); - this.clearMobileLaunchArtifacts(); this.authService.hideLogin(); this.stopPolling(); } @@ -88,7 +80,7 @@ export class TelegramLoginComponent implements OnDestroy { if (this.isMobileBrowser()) { this.awaitingTelegramReturn.set(true); - this.launchTelegramApp(webSessionID); + window.location.href = this.authService.getTelegramAppLoginUrl(webSessionID); return; } @@ -97,14 +89,12 @@ export class TelegramLoginComponent implements OnDestroy { refreshQr(): void { this.awaitingTelegramReturn.set(false); - this.clearMobileLaunchArtifacts(); this.stopPolling(); this.initQrLogin(); } private initQrLogin(): void { this.awaitingTelegramReturn.set(false); - this.clearMobileLaunchArtifacts(); this.qrStatus.set('loading'); this.loginUrl.set(''); this.webSessionID.set(''); @@ -139,7 +129,6 @@ export class TelegramLoginComponent implements OnDestroy { next: (session) => { if (session?.active) { this.awaitingTelegramReturn.set(false); - this.clearMobileLaunchArtifacts(); this.stopPolling(); this.authService.onTelegramLoginComplete(); } @@ -176,46 +165,12 @@ export class TelegramLoginComponent implements OnDestroy { this.authService.checkSessionOnce(webSessionID).subscribe(session => { if (session?.active) { this.awaitingTelegramReturn.set(false); - this.clearMobileLaunchArtifacts(); this.stopPolling(); this.authService.onTelegramLoginComplete(); } }); } - private launchTelegramApp(webSessionID: string): void { - if (typeof document === 'undefined') { - return; - } - - this.clearMobileLaunchArtifacts(); - - this.launchFrame = document.createElement('iframe'); - this.launchFrame.style.display = 'none'; - this.launchFrame.setAttribute('aria-hidden', 'true'); - this.launchFrame.setAttribute('tabindex', '-1'); - this.launchFrame.src = this.authService.getTelegramAppLoginUrl(webSessionID); - document.body.appendChild(this.launchFrame); - - this.mobileFallbackTimeout = setTimeout(() => { - this.removeLaunchFrame(); - }, 1400); - } - - private clearMobileLaunchArtifacts(): void { - if (this.mobileFallbackTimeout) { - clearTimeout(this.mobileFallbackTimeout); - this.mobileFallbackTimeout = undefined; - } - - this.removeLaunchFrame(); - } - - private removeLaunchFrame(): void { - this.launchFrame?.remove(); - this.launchFrame = undefined; - } - private isMobileBrowser(): boolean { if (typeof navigator === 'undefined') { return false;