signal-desktop/ts/components/DialogUpdate.tsx

241 lines
6.1 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import formatFileSize from 'filesize';
2021-11-11 22:46:16 +00:00
import { isBeta } from '../util/version';
import { DialogType } from '../types/Dialogs';
import type { LocalizerType } from '../types/Util';
2021-09-17 22:20:49 +00:00
import { Intl } from './Intl';
import { LeftPaneDialog } from './LeftPaneDialog';
import type { WidthBreakpoint } from './_util';
export type PropsType = {
containerWidthBreakpoint: WidthBreakpoint;
dialogType: DialogType;
didSnooze: boolean;
dismissDialog: () => void;
downloadSize?: number;
downloadedSize?: number;
hasNetworkDialog: boolean;
i18n: LocalizerType;
showEventsCount: number;
snoozeUpdate: () => void;
startUpdate: () => void;
version?: string;
2021-11-11 22:46:16 +00:00
currentVersion: string;
};
2021-11-11 22:46:16 +00:00
const PRODUCTION_DOWNLOAD_URL = 'https://signal.org/download/';
const BETA_DOWNLOAD_URL = 'https://support.signal.org/beta';
export const DialogUpdate = ({
containerWidthBreakpoint,
dialogType,
didSnooze,
dismissDialog,
downloadSize,
downloadedSize,
hasNetworkDialog,
i18n,
snoozeUpdate,
startUpdate,
version,
2021-11-11 22:46:16 +00:00
currentVersion,
}: PropsType): JSX.Element | null => {
if (hasNetworkDialog) {
return null;
}
if (dialogType === DialogType.None) {
return null;
}
if (didSnooze) {
return null;
}
if (dialogType === DialogType.Cannot_Update) {
2021-11-11 22:46:16 +00:00
const url = isBeta(currentVersion)
? BETA_DOWNLOAD_URL
: PRODUCTION_DOWNLOAD_URL;
return (
<LeftPaneDialog
containerWidthBreakpoint={containerWidthBreakpoint}
type="warning"
title={i18n('cannotUpdate')}
>
2021-09-17 22:20:49 +00:00
<span>
<Intl
2022-02-02 21:13:56 +00:00
components={{
retry: (
<button
className="LeftPaneDialog__retry"
key="signal-retry"
onClick={startUpdate}
type="button"
>
{i18n('autoUpdateRetry')}
</button>
),
url: (
<a
key="signal-download"
href={url}
rel="noreferrer"
target="_blank"
>
{url}
</a>
),
support: (
<a
key="signal-support"
href="https://support.signal.org/hc/en-us/requests/new?desktop"
rel="noreferrer"
target="_blank"
>
{i18n('autoUpdateContactSupport')}
</a>
),
}}
2021-09-17 22:20:49 +00:00
i18n={i18n}
id="cannotUpdateDetail"
/>
</span>
</LeftPaneDialog>
);
}
if (dialogType === DialogType.Cannot_Update_Require_Manual) {
const url = isBeta(currentVersion)
? BETA_DOWNLOAD_URL
: PRODUCTION_DOWNLOAD_URL;
return (
<LeftPaneDialog
containerWidthBreakpoint={containerWidthBreakpoint}
type="warning"
title={i18n('cannotUpdate')}
>
<span>
<Intl
components={{
url: (
<a
key="signal-download"
href={url}
rel="noreferrer"
target="_blank"
>
{url}
</a>
),
support: (
<a
key="signal-support"
href="https://support.signal.org/hc/en-us/requests/new?desktop"
rel="noreferrer"
target="_blank"
>
{i18n('autoUpdateContactSupport')}
</a>
),
}}
i18n={i18n}
id="cannotUpdateRequireManualDetail"
/>
</span>
</LeftPaneDialog>
);
}
if (dialogType === DialogType.MacOS_Read_Only) {
return (
2021-09-17 22:20:49 +00:00
<LeftPaneDialog
2022-02-02 21:13:56 +00:00
closeLabel={i18n('close')}
containerWidthBreakpoint={containerWidthBreakpoint}
2021-09-17 22:20:49 +00:00
hasXButton
onClose={dismissDialog}
2022-02-02 21:13:56 +00:00
title={i18n('cannotUpdate')}
type="warning"
2021-09-17 22:20:49 +00:00
>
<span>
<Intl
components={{
app: <strong key="app">Signal.app</strong>,
folder: <strong key="folder">/Applications</strong>,
}}
i18n={i18n}
id="readOnlyVolume"
/>
2021-09-17 22:20:49 +00:00
</span>
</LeftPaneDialog>
);
}
2021-09-17 22:20:49 +00:00
let title = i18n('autoUpdateNewVersionTitle');
if (
downloadSize &&
(dialogType === DialogType.DownloadReady ||
dialogType === DialogType.FullDownloadReady ||
dialogType === DialogType.Downloading)
) {
2021-09-17 22:20:49 +00:00
title += ` (${formatFileSize(downloadSize, { round: 0 })})`;
}
2021-09-17 22:20:49 +00:00
const versionTitle = version
? i18n('DialogUpdate--version-available', [version])
: undefined;
if (dialogType === DialogType.Downloading) {
const width = Math.ceil(
((downloadedSize || 1) / (downloadSize || 1)) * 100
);
2021-09-17 22:20:49 +00:00
return (
<LeftPaneDialog
containerWidthBreakpoint={containerWidthBreakpoint}
icon="update"
title={title}
hoverText={versionTitle}
>
2021-09-17 22:20:49 +00:00
<div className="LeftPaneDialog__progress--container">
<div
className="LeftPaneDialog__progress--bar"
style={{ width: `${width}%` }}
/>
</div>
</LeftPaneDialog>
);
}
2021-09-17 22:20:49 +00:00
let clickLabel: string;
let type: 'warning' | undefined;
2021-09-17 22:20:49 +00:00
if (dialogType === DialogType.DownloadReady) {
clickLabel = i18n('downloadNewVersionMessage');
} else if (dialogType === DialogType.FullDownloadReady) {
clickLabel = i18n('downloadFullNewVersionMessage');
type = 'warning';
2021-09-17 22:20:49 +00:00
} else {
clickLabel = i18n('autoUpdateNewVersionMessage');
}
return (
2021-09-17 22:20:49 +00:00
<LeftPaneDialog
containerWidthBreakpoint={containerWidthBreakpoint}
2021-09-17 22:20:49 +00:00
icon="update"
type={type}
2021-09-17 22:20:49 +00:00
title={title}
hoverText={versionTitle}
hasAction
onClick={startUpdate}
clickLabel={clickLabel}
hasXButton
onClose={snoozeUpdate}
closeLabel={i18n('autoUpdateIgnoreButtonLabel')}
/>
);
};