// Copyright 2020-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import formatFileSize from 'filesize';
import { DialogType } from '../types/Dialogs';
import { Intl } from './Intl';
import { LocalizerType } from '../types/Util';
export type PropsType = {
dialogType: DialogType;
didSnooze: boolean;
dismissDialog: () => void;
downloadSize?: number;
downloadedSize?: number;
hasNetworkDialog: boolean;
i18n: LocalizerType;
showEventsCount: number;
snoozeUpdate: () => void;
startUpdate: () => void;
version?: string;
};
export const DialogUpdate = ({
dialogType,
didSnooze,
dismissDialog,
downloadSize,
downloadedSize,
hasNetworkDialog,
i18n,
snoozeUpdate,
startUpdate,
version,
}: PropsType): JSX.Element | null => {
if (hasNetworkDialog) {
return null;
}
if (dialogType === DialogType.None) {
return null;
}
if (didSnooze) {
return null;
}
if (dialogType === DialogType.Cannot_Update) {
return (
{i18n('cannotUpdate')}
https://signal.org/download/
,
]}
i18n={i18n}
id="cannotUpdateDetail"
/>
);
}
if (dialogType === DialogType.MacOS_Read_Only) {
return (
{i18n('cannotUpdate')}
Signal.app,
folder: /Applications,
}}
i18n={i18n}
id="readOnlyVolume"
/>
);
}
let size: string | undefined;
if (
downloadSize &&
(dialogType === DialogType.DownloadReady ||
dialogType === DialogType.Downloading)
) {
size = `(${formatFileSize(downloadSize, { round: 0 })})`;
}
let updateSubText: JSX.Element;
if (dialogType === DialogType.DownloadReady) {
updateSubText = (
);
} else if (dialogType === DialogType.Downloading) {
const width = Math.ceil(
((downloadedSize || 1) / (downloadSize || 1)) * 100
);
updateSubText = (
);
} else {
updateSubText = (
);
}
const versionTitle = version
? i18n('DialogUpdate--version-available', [version])
: undefined;
return (
{i18n('autoUpdateNewVersionTitle')} {size}
{updateSubText}
{dialogType !== DialogType.Downloading && (
)}
);
};