signal-desktop/ts/components/installScreen/InstallScreenErrorStep.tsx

104 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-12-16 15:02:22 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { type ReactElement, useEffect, useCallback } from 'react';
import { noop } from 'lodash';
2021-12-16 15:02:22 +00:00
import type { LocalizerType } from '../../types/Util';
import { missingCaseError } from '../../util/missingCaseError';
import { openLinkInWebBrowser } from '../../util/openLinkInWebBrowser';
import { Button, ButtonVariant } from '../Button';
import { TitlebarDragArea } from '../TitlebarDragArea';
import { InstallScreenSignalLogo } from './InstallScreenSignalLogo';
import { LINK_SIGNAL_DESKTOP } from '../../types/support';
2024-09-04 02:56:13 +00:00
import { InstallScreenError } from '../../types/InstallScreen';
2021-12-16 15:02:22 +00:00
export type Props = Readonly<{
2024-09-04 02:56:13 +00:00
error: InstallScreenError;
i18n: LocalizerType;
quit: () => unknown;
tryAgain: () => unknown;
}>;
2021-12-16 15:02:22 +00:00
export function InstallScreenErrorStep({
error,
i18n,
quit,
tryAgain,
}: Props): ReactElement {
2021-12-16 15:02:22 +00:00
let errorMessage: string;
2023-03-30 00:03:25 +00:00
let buttonText = i18n('icu:installTryAgain');
let onClickButton = useCallback(() => tryAgain(), [tryAgain]);
2021-12-16 15:02:22 +00:00
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]);
2021-12-16 15:02:22 +00:00
switch (error) {
2024-09-04 02:56:13 +00:00
case InstallScreenError.TooManyDevices:
2023-03-30 00:03:25 +00:00
errorMessage = i18n('icu:installTooManyDevices');
2021-12-16 15:02:22 +00:00
break;
2024-09-04 02:56:13 +00:00
case InstallScreenError.TooOld:
2023-03-30 00:03:25 +00:00
errorMessage = i18n('icu:installTooOld');
buttonText = i18n('icu:upgrade');
2021-12-16 15:02:22 +00:00
onClickButton = () => {
openLinkInWebBrowser('https://signal.org/download');
};
shouldShowQuitButton = true;
break;
2024-09-04 02:56:13 +00:00
case InstallScreenError.ConnectionFailed:
case InstallScreenError.InactiveTimeout:
2023-03-30 00:03:25 +00:00
errorMessage = i18n('icu:installConnectionFailed');
2021-12-16 15:02:22 +00:00
break;
2024-09-04 02:56:13 +00:00
case InstallScreenError.QRCodeFailed:
buttonText = i18n('icu:Install__learn-more');
errorMessage = i18n('icu:installUnknownError');
onClickButton = () => {
openLinkInWebBrowser(LINK_SIGNAL_DESKTOP);
};
shouldShowQuitButton = true;
break;
2021-12-16 15:02:22 +00:00
default:
throw missingCaseError(error);
}
return (
<div className="module-InstallScreenErrorStep">
<TitlebarDragArea />
<InstallScreenSignalLogo />
2023-03-30 00:03:25 +00:00
<h1>{i18n('icu:installErrorHeader')}</h1>
2021-12-16 15:02:22 +00:00
<h2>{errorMessage}</h2>
<div className="module-InstallScreenErrorStep__buttons">
<Button onClick={onClickButton}>{buttonText}</Button>
{shouldShowQuitButton && (
<Button onClick={() => quit()} variant={ButtonVariant.Secondary}>
2023-03-30 00:03:25 +00:00
{i18n('icu:quit')}
2021-12-16 15:02:22 +00:00
</Button>
)}
</div>
</div>
);
}