From fb04b1ede313d8a91b613f7485b81b353e3fe3f8 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 28 Jan 2025 09:11:22 -0800 Subject: [PATCH] Fix QR-code auto-retry logic --- .../installScreen/InstallScreenErrorStep.tsx | 26 +-------------- .../InstallScreenQrCodeNotScannedStep.tsx | 33 ++++++++++++++++--- ts/types/InstallScreen.ts | 1 - 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/ts/components/installScreen/InstallScreenErrorStep.tsx b/ts/components/installScreen/InstallScreenErrorStep.tsx index 15e2fc019d..b9cc4c2d6d 100644 --- a/ts/components/installScreen/InstallScreenErrorStep.tsx +++ b/ts/components/installScreen/InstallScreenErrorStep.tsx @@ -1,8 +1,7 @@ // Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import React, { type ReactElement, useEffect, useCallback } from 'react'; -import { noop } from 'lodash'; +import React, { type ReactElement, useCallback } from 'react'; import type { LocalizerType } from '../../types/Util'; import { missingCaseError } from '../../util/missingCaseError'; @@ -31,28 +30,6 @@ export function InstallScreenErrorStep({ let onClickButton = useCallback(() => tryAgain(), [tryAgain]); let shouldShowQuitButton = false; - useEffect(() => { - if (error !== InstallScreenError.InactiveTimeout) { - return noop; - } - - const cleanup = () => { - document.removeEventListener('visibilitychange', onVisibilityChange); - }; - - const onVisibilityChange = () => { - if (document.hidden) { - return; - } - - cleanup(); - tryAgain(); - }; - - document.addEventListener('visibilitychange', onVisibilityChange); - return cleanup; - }, [error, tryAgain]); - switch (error) { case InstallScreenError.TooManyDevices: errorMessage = i18n('icu:installTooManyDevices'); @@ -66,7 +43,6 @@ export function InstallScreenErrorStep({ shouldShowQuitButton = true; break; case InstallScreenError.ConnectionFailed: - case InstallScreenError.InactiveTimeout: errorMessage = i18n('icu:installConnectionFailed'); break; case InstallScreenError.QRCodeFailed: diff --git a/ts/components/installScreen/InstallScreenQrCodeNotScannedStep.tsx b/ts/components/installScreen/InstallScreenQrCodeNotScannedStep.tsx index c9c7e1d26a..13180f9a4d 100644 --- a/ts/components/installScreen/InstallScreenQrCodeNotScannedStep.tsx +++ b/ts/components/installScreen/InstallScreenQrCodeNotScannedStep.tsx @@ -132,10 +132,35 @@ function InstallScreenQrCode( retryGetQrCode: () => void; } ): ReactElement { - const { i18n } = props; + const { i18n, retryGetQrCode } = props; let contents: ReactNode; + const loadError = + props.loadingState === LoadingState.LoadFailed ? props.error : undefined; + + useEffect(() => { + if (loadError !== InstallScreenQRCodeError.MaxRotations) { + return noop; + } + + const cleanup = () => { + document.removeEventListener('visibilitychange', onVisibilityChange); + }; + + const onVisibilityChange = () => { + if (document.hidden) { + return; + } + + cleanup(); + retryGetQrCode(); + }; + + document.addEventListener('visibilitychange', onVisibilityChange); + return cleanup; + }, [retryGetQrCode, loadError]); + let isJustButton = false; switch (props.loadingState) { case LoadingState.Loading: @@ -151,7 +176,7 @@ function InstallScreenQrCode( > {i18n('icu:Install__qr-failed-load__error--timeout')} - + {i18n('icu:Install__qr-failed-load__retry')} @@ -169,7 +194,7 @@ function InstallScreenQrCode( components={{ paragraph: Paragraph }} /> - + {i18n('icu:Install__qr-failed-load__retry')} @@ -198,7 +223,7 @@ function InstallScreenQrCode( case InstallScreenQRCodeError.MaxRotations: isJustButton = true; contents = ( - + {i18n('icu:Install__qr-max-rotations__retry')} ); diff --git a/ts/types/InstallScreen.ts b/ts/types/InstallScreen.ts index f4ae78685a..a1e006400b 100644 --- a/ts/types/InstallScreen.ts +++ b/ts/types/InstallScreen.ts @@ -29,7 +29,6 @@ export enum InstallScreenError { TooOld = 'TooOld', ConnectionFailed = 'ConnectionFailed', QRCodeFailed = 'QRCodeFailed', - InactiveTimeout = 'InactiveTimeout', } export enum InstallScreenQRCodeError {