// Copyright 2020-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import formatFileSize from 'filesize';
import { isBeta } from '../util/version';
import { DialogType } from '../types/Dialogs';
import type { LocalizerType } from '../types/Util';
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;
currentVersion: string;
};
const PRODUCTION_DOWNLOAD_URL = 'https://signal.org/download/';
const BETA_DOWNLOAD_URL = 'https://support.signal.org/beta';
export function DialogUpdate({
containerWidthBreakpoint,
dialogType,
didSnooze,
dismissDialog,
downloadSize,
downloadedSize,
hasNetworkDialog,
i18n,
snoozeUpdate,
startUpdate,
version,
currentVersion,
}: PropsType): JSX.Element | null {
if (hasNetworkDialog) {
return null;
}
if (dialogType === DialogType.None) {
return null;
}
if (didSnooze) {
return null;
}
if (dialogType === DialogType.Cannot_Update) {
const url = isBeta(currentVersion)
? BETA_DOWNLOAD_URL
: PRODUCTION_DOWNLOAD_URL;
return (
{i18n('autoUpdateRetry')}
),
url: (
{url}
),
support: (
{i18n('autoUpdateContactSupport')}
),
}}
i18n={i18n}
id="cannotUpdateDetail"
/>
);
}
if (dialogType === DialogType.Cannot_Update_Require_Manual) {
const url = isBeta(currentVersion)
? BETA_DOWNLOAD_URL
: PRODUCTION_DOWNLOAD_URL;
return (
{url}
),
support: (
{i18n('autoUpdateContactSupport')}
),
}}
i18n={i18n}
id="cannotUpdateRequireManualDetail"
/>
);
}
if (dialogType === DialogType.MacOS_Read_Only) {
return (
Signal.app,
folder: /Applications,
}}
i18n={i18n}
id="readOnlyVolume"
/>
);
}
let title = i18n('autoUpdateNewVersionTitle');
if (
downloadSize &&
(dialogType === DialogType.DownloadReady ||
dialogType === DialogType.FullDownloadReady ||
dialogType === DialogType.Downloading)
) {
title += ` (${formatFileSize(downloadSize, { round: 0 })})`;
}
const versionTitle = version
? i18n('DialogUpdate--version-available', [version])
: undefined;
if (dialogType === DialogType.Downloading) {
const width = Math.ceil(
((downloadedSize || 1) / (downloadSize || 1)) * 100
);
return (
);
}
let clickLabel: string;
let type: 'warning' | undefined;
if (dialogType === DialogType.DownloadReady) {
clickLabel = i18n('downloadNewVersionMessage');
} else if (dialogType === DialogType.FullDownloadReady) {
clickLabel = i18n('downloadFullNewVersionMessage');
type = 'warning';
} else {
clickLabel = i18n('autoUpdateNewVersionMessage');
}
return (
);
}