Fix QR-code auto-retry logic
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
539ebb14dd
commit
e646d25b56
3 changed files with 30 additions and 30 deletions
|
@ -1,8 +1,7 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import React, { type ReactElement, useEffect, useCallback } from 'react';
|
import React, { type ReactElement, useCallback } from 'react';
|
||||||
import { noop } from 'lodash';
|
|
||||||
|
|
||||||
import type { LocalizerType } from '../../types/Util';
|
import type { LocalizerType } from '../../types/Util';
|
||||||
import { missingCaseError } from '../../util/missingCaseError';
|
import { missingCaseError } from '../../util/missingCaseError';
|
||||||
|
@ -31,28 +30,6 @@ export function InstallScreenErrorStep({
|
||||||
let onClickButton = useCallback(() => tryAgain(), [tryAgain]);
|
let onClickButton = useCallback(() => tryAgain(), [tryAgain]);
|
||||||
let shouldShowQuitButton = false;
|
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) {
|
switch (error) {
|
||||||
case InstallScreenError.TooManyDevices:
|
case InstallScreenError.TooManyDevices:
|
||||||
errorMessage = i18n('icu:installTooManyDevices');
|
errorMessage = i18n('icu:installTooManyDevices');
|
||||||
|
@ -66,7 +43,6 @@ export function InstallScreenErrorStep({
|
||||||
shouldShowQuitButton = true;
|
shouldShowQuitButton = true;
|
||||||
break;
|
break;
|
||||||
case InstallScreenError.ConnectionFailed:
|
case InstallScreenError.ConnectionFailed:
|
||||||
case InstallScreenError.InactiveTimeout:
|
|
||||||
errorMessage = i18n('icu:installConnectionFailed');
|
errorMessage = i18n('icu:installConnectionFailed');
|
||||||
break;
|
break;
|
||||||
case InstallScreenError.QRCodeFailed:
|
case InstallScreenError.QRCodeFailed:
|
||||||
|
|
|
@ -132,10 +132,35 @@ function InstallScreenQrCode(
|
||||||
retryGetQrCode: () => void;
|
retryGetQrCode: () => void;
|
||||||
}
|
}
|
||||||
): ReactElement {
|
): ReactElement {
|
||||||
const { i18n } = props;
|
const { i18n, retryGetQrCode } = props;
|
||||||
|
|
||||||
let contents: ReactNode;
|
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;
|
let isJustButton = false;
|
||||||
switch (props.loadingState) {
|
switch (props.loadingState) {
|
||||||
case LoadingState.Loading:
|
case LoadingState.Loading:
|
||||||
|
@ -151,7 +176,7 @@ function InstallScreenQrCode(
|
||||||
>
|
>
|
||||||
{i18n('icu:Install__qr-failed-load__error--timeout')}
|
{i18n('icu:Install__qr-failed-load__error--timeout')}
|
||||||
</span>
|
</span>
|
||||||
<RetryButton onClick={props.retryGetQrCode}>
|
<RetryButton onClick={retryGetQrCode}>
|
||||||
{i18n('icu:Install__qr-failed-load__retry')}
|
{i18n('icu:Install__qr-failed-load__retry')}
|
||||||
</RetryButton>
|
</RetryButton>
|
||||||
</>
|
</>
|
||||||
|
@ -169,7 +194,7 @@ function InstallScreenQrCode(
|
||||||
components={{ paragraph: Paragraph }}
|
components={{ paragraph: Paragraph }}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
<RetryButton onClick={props.retryGetQrCode}>
|
<RetryButton onClick={retryGetQrCode}>
|
||||||
{i18n('icu:Install__qr-failed-load__retry')}
|
{i18n('icu:Install__qr-failed-load__retry')}
|
||||||
</RetryButton>
|
</RetryButton>
|
||||||
</>
|
</>
|
||||||
|
@ -198,7 +223,7 @@ function InstallScreenQrCode(
|
||||||
case InstallScreenQRCodeError.MaxRotations:
|
case InstallScreenQRCodeError.MaxRotations:
|
||||||
isJustButton = true;
|
isJustButton = true;
|
||||||
contents = (
|
contents = (
|
||||||
<RetryButton onClick={props.retryGetQrCode}>
|
<RetryButton onClick={retryGetQrCode}>
|
||||||
{i18n('icu:Install__qr-max-rotations__retry')}
|
{i18n('icu:Install__qr-max-rotations__retry')}
|
||||||
</RetryButton>
|
</RetryButton>
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,7 +29,6 @@ export enum InstallScreenError {
|
||||||
TooOld = 'TooOld',
|
TooOld = 'TooOld',
|
||||||
ConnectionFailed = 'ConnectionFailed',
|
ConnectionFailed = 'ConnectionFailed',
|
||||||
QRCodeFailed = 'QRCodeFailed',
|
QRCodeFailed = 'QRCodeFailed',
|
||||||
InactiveTimeout = 'InactiveTimeout',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum InstallScreenQRCodeError {
|
export enum InstallScreenQRCodeError {
|
||||||
|
|
Loading…
Reference in a new issue