import { mdiDownload } from '@mdi/js'; import CancelIcon from '@mui/icons-material/Cancel'; import ClearAllIcon from '@mui/icons-material/ClearAll'; import DeleteIcon from '@mui/icons-material/Delete'; import FolderIcon from '@mui/icons-material/Folder'; import PauseIcon from '@mui/icons-material/Pause'; import PlayArrowIcon from '@mui/icons-material/PlayArrow'; import { Box, Card, CardContent, IconButton, LinearProgress, ListItemButton, ListItemIcon, ListItemText, Typography, } from '@mui/material'; import { shell } from 'electron'; import { round } from 'lodash'; import { observer } from 'mobx-react'; import prettyBytes from 'pretty-bytes'; import { Component } from 'react'; import { type IntlShape, defineMessages, injectIntl } from 'react-intl'; import type { Actions } from '../../actions/lib/actions'; import type { RealStores } from '../../stores'; import Icon from '../ui/icon'; const messages = defineMessages({ headline: { id: 'downloadManager.headline', defaultMessage: 'Download Manager', }, empty: { id: 'downloadManager.empty', defaultMessage: 'Your download list is empty.', }, }); interface IProps { intl: IntlShape; stores?: RealStores; actions?: Actions; } interface IState { data: string; } // eslint-disable-next-line react/prefer-stateless-function class DownloadManagerDashboard extends Component { render() { const { intl, stores, actions } = this.props; const downloads = stores?.app.downloads ?? []; return (
{intl.formatMessage(messages.headline)} beta
{downloads.length === 0 ? ( {intl.formatMessage(messages.empty)} ) : ( { actions?.app.removeDownload(null); }} > )} {downloads.map(download => { const { totalBytes, receivedBytes, filename, url, savePath, state, id, paused, } = download; const downloadPercentage = receivedBytes !== undefined && totalBytes !== undefined ? round((receivedBytes / totalBytes) * 100, 2) : null; const stateParse = state === 'progressing' ? paused === false || paused === undefined ? null : 'Paused' : state === 'cancelled' ? 'Cancelled' : state === 'completed' ? null : 'Error'; return ( {stateParse !== null && stateParse !== 'Paused' ? stateParse : stateParse === 'Paused' ? stateParse : null} {url} {`${ downloadPercentage ? `${downloadPercentage}% - ` : '' }${ receivedBytes ? `${prettyBytes(receivedBytes)} of ` : '' }${totalBytes ? prettyBytes(totalBytes) : ''}`} {state !== 'completed' && state !== 'cancelled' && ( { actions?.app.stopDownload(id); }} > )} {state === 'progressing' && ( { actions?.app.togglePauseDownload(id); }} > {(paused === false || paused === undefined) && ( )} {paused && } )} {(state === 'cancelled' || state === 'completed') && ( { actions?.app.removeDownload(id); }} size="small" > )} {state !== 'cancelled' && ( { if (savePath) shell.showItemInFolder(savePath); }} size="small" > )} ); })}
); } } export default injectIntl(observer(DownloadManagerDashboard));