// Copyright 2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import type { ReactNode } from 'react'; import React, { useCallback } from 'react'; import { isBeta } from '../util/version'; import { DialogType } from '../types/Dialogs'; import type { LocalizerType } from '../types/Util'; import { PRODUCTION_DOWNLOAD_URL, BETA_DOWNLOAD_URL } from '../types/support'; import { I18n } from './I18n'; import { LeftPaneDialog } from './LeftPaneDialog'; import type { WidthBreakpoint } from './_util'; import { formatFileSize } from '../util/formatFileSize'; function contactSupportLink(parts: ReactNode): JSX.Element { return ( {parts} ); } export type PropsType = { containerWidthBreakpoint: WidthBreakpoint; dialogType: DialogType; dismissDialog: () => void; downloadSize?: number; downloadedSize?: number; i18n: LocalizerType; snoozeUpdate: () => void; startUpdate: () => void; version?: string; currentVersion: string; }; export function DialogUpdate({ containerWidthBreakpoint, dialogType, dismissDialog, downloadSize, downloadedSize, i18n, snoozeUpdate, startUpdate, version, currentVersion, }: PropsType): JSX.Element | null { const retryUpdateButton = useCallback( (parts: ReactNode): JSX.Element => { return ( ); }, [startUpdate] ); if (dialogType === DialogType.Cannot_Update) { const url = isBeta(currentVersion) ? BETA_DOWNLOAD_URL : PRODUCTION_DOWNLOAD_URL; return ( {url} ), contactSupportLink, }} i18n={i18n} id="icu:cannotUpdateDetail-v2" /> ); } if (dialogType === DialogType.Cannot_Update_Require_Manual) { const url = isBeta(currentVersion) ? BETA_DOWNLOAD_URL : PRODUCTION_DOWNLOAD_URL; return ( {url} ), contactSupportLink, }} i18n={i18n} id="icu:cannotUpdateRequireManualDetail-v2" /> ); } if (dialogType === DialogType.MacOS_Read_Only) { return ( Signal.app, folder: /Applications, }} i18n={i18n} id="icu:readOnlyVolume" /> ); } if (dialogType === DialogType.UnsupportedOS) { // Displayed as UnsupportedOSDialog in LeftPane return null; } const versionTitle = version ? i18n('icu:DialogUpdate--version-available', { version, }) : undefined; if (dialogType === DialogType.Downloading) { const width = Math.ceil( ((downloadedSize || 1) / (downloadSize || 1)) * 100 ); return (
); } let title = i18n('icu:autoUpdateNewVersionTitle'); if ( downloadSize && (dialogType === DialogType.DownloadReady || dialogType === DialogType.FullDownloadReady) ) { title += ` (${formatFileSize(downloadSize)})`; } let clickLabel = i18n('icu:autoUpdateNewVersionMessage'); let type: 'warning' | undefined; if (dialogType === DialogType.DownloadReady) { clickLabel = i18n('icu:downloadNewVersionMessage'); } else if (dialogType === DialogType.FullDownloadReady) { clickLabel = i18n('icu:downloadFullNewVersionMessage'); type = 'warning'; } else if (dialogType === DialogType.DownloadedUpdate) { title = i18n('icu:DialogUpdate__downloaded'); } return ( ); }