// Copyright 2023 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import { noop } from 'lodash'; import type { FormatXMLElementFn } from 'intl-messageformat'; import formatFileSize from 'filesize'; import { DialogType } from '../../types/Dialogs'; import type { LocalizerType } from '../../types/Util'; import { PRODUCTION_DOWNLOAD_URL, BETA_DOWNLOAD_URL, UNSUPPORTED_OS_URL, } from '../../types/support'; import type { UpdatesStateType } from '../../state/ducks/updates'; import { isBeta } from '../../util/version'; import { ConfirmationDialog } from '../ConfirmationDialog'; import { Modal } from '../Modal'; import { Intl } from '../Intl'; export type PropsType = UpdatesStateType & Readonly<{ i18n: LocalizerType; startUpdate: () => void; currentVersion: string; OS: string; }>; export function InstallScreenUpdateDialog({ i18n, dialogType, downloadSize, downloadedSize, startUpdate, currentVersion, OS, }: PropsType): JSX.Element | null { const learnMoreLink: FormatXMLElementFn = children => ( {children} ); const dialogName = `InstallScreenUpdateDialog.${dialogType}`; if (dialogType === DialogType.UnsupportedOS) { return ( ); } if ( dialogType === DialogType.AutoUpdate || // Manual update with an action button dialogType === DialogType.DownloadReady || dialogType === DialogType.FullDownloadReady || dialogType === DialogType.DownloadedUpdate ) { let title = i18n('icu:autoUpdateNewVersionTitle'); let actionText: string | JSX.Element = i18n( 'icu:autoUpdateRestartButtonLabel' ); let bodyText = i18n('icu:InstallScreenUpdateDialog--auto-update__body'); if ( dialogType === DialogType.DownloadReady || dialogType === DialogType.FullDownloadReady ) { actionText = ( ({formatFileSize(downloadSize ?? 0, { round: 0 })}) ), }} /> ); } if (dialogType === DialogType.DownloadedUpdate) { title = i18n('icu:DialogUpdate__downloaded'); bodyText = i18n('icu:InstallScreenUpdateDialog--downloaded__body'); } return ( {bodyText} ); } if (dialogType === DialogType.Downloading) { // Focus trap can't be used because there are no elements that can be // focused within the modal. const width = Math.ceil( ((downloadedSize || 1) / (downloadSize || 1)) * 100 ); return (
); } if ( dialogType === DialogType.Cannot_Update || dialogType === DialogType.Cannot_Update_Require_Manual ) { const url = isBeta(currentVersion) ? BETA_DOWNLOAD_URL : PRODUCTION_DOWNLOAD_URL; const title = i18n('icu:cannotUpdate'); const body = ( {url} ), }} /> ); if (dialogType === DialogType.Cannot_Update) { return ( {body} ); } return ( {body} ); } if (dialogType === DialogType.MacOS_Read_Only) { // No focus trap, because there are no focusable elements. return ( Signal.app, folder: /Applications, }} i18n={i18n} id="icu:readOnlyVolume" /> ); } return null; }