Fix QR-code auto-retry logic

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2025-01-28 15:17:02 -06:00 committed by GitHub
parent 539ebb14dd
commit e646d25b56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 30 deletions

View file

@ -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:

View file

@ -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')}
</span>
<RetryButton onClick={props.retryGetQrCode}>
<RetryButton onClick={retryGetQrCode}>
{i18n('icu:Install__qr-failed-load__retry')}
</RetryButton>
</>
@ -169,7 +194,7 @@ function InstallScreenQrCode(
components={{ paragraph: Paragraph }}
/>
</span>
<RetryButton onClick={props.retryGetQrCode}>
<RetryButton onClick={retryGetQrCode}>
{i18n('icu:Install__qr-failed-load__retry')}
</RetryButton>
</>
@ -198,7 +223,7 @@ function InstallScreenQrCode(
case InstallScreenQRCodeError.MaxRotations:
isJustButton = true;
contents = (
<RetryButton onClick={props.retryGetQrCode}>
<RetryButton onClick={retryGetQrCode}>
{i18n('icu:Install__qr-max-rotations__retry')}
</RetryButton>
);

View file

@ -29,7 +29,6 @@ export enum InstallScreenError {
TooOld = 'TooOld',
ConnectionFailed = 'ConnectionFailed',
QRCodeFailed = 'QRCodeFailed',
InactiveTimeout = 'InactiveTimeout',
}
export enum InstallScreenQRCodeError {