remove downloads frontend

This commit is contained in:
SpikeHD
2022-05-12 21:20:43 -07:00
parent f9f3461da5
commit 2bcb68ba32
3 changed files with 18 additions and 4 deletions

View File

@@ -36,7 +36,7 @@ async function TESTDOWNLOAD() {
download( download(
'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/stable.zip', 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/stable.zip',
'grasscutter.zip', 'grasscutter.zip',
'C:\\Users\\spike\\Documents\\dev\\Cultivation' 'S:\\Cultivation'
) )
} }

View File

@@ -3,10 +3,11 @@ import { capitalize } from '../../../utils/string'
import Stop from '../../../resources/icons/close.svg' import Stop from '../../../resources/icons/close.svg'
import './ProgressBar.css' import './ProgressBar.css'
import DownloadHandler from '../../../utils/download'
interface IProps { interface IProps {
path: string, path: string,
downloadManager: any, downloadManager: DownloadHandler,
} }
interface IState { interface IState {
@@ -31,7 +32,7 @@ export default class ProgressBar extends React.Component<IProps, IState> {
const intv = setInterval(() => { const intv = setInterval(() => {
const prog = this.props.downloadManager.getDownloadProgress(this.props.path) const prog = this.props.downloadManager.getDownloadProgress(this.props.path)
this.setState({ this.setState({
progress: parseInt(prog?.progress || 0, 10), progress: prog?.progress || 0,
status: prog?.status || 'error', status: prog?.status || 'error',
total: prog?.total || 0, total: prog?.total || 0,
}) })
@@ -43,6 +44,10 @@ export default class ProgressBar extends React.Component<IProps, IState> {
}, 500) }, 500)
} }
stopDownload() {
this.props.downloadManager.stopDownload(this.props.path)
}
render() { render() {
return ( return (
<div className="ProgressBarWrapper"> <div className="ProgressBarWrapper">
@@ -66,7 +71,7 @@ export default class ProgressBar extends React.Component<IProps, IState> {
}}></div> }}></div>
</div> </div>
<div className="DownloadControls"> <div className="DownloadControls">
<div> <div onClick={this.stopDownload}>
<img src={Stop}></img> <img src={Stop}></img>
</div> </div>
</div> </div>

View File

@@ -69,6 +69,15 @@ export default class DownloadHandler {
this.downloads.push(obj) this.downloads.push(obj)
} }
stopDownload(path: string) {
// Stop download and remove from list.
invoke('stop_download', { path })
// Remove from list
const index = this.downloads.findIndex(download => download.path === path)
this.downloads.splice(index, 1)
}
getDownloadProgress(path: string) { getDownloadProgress(path: string) {
const index = this.downloads.findIndex(download => download.path === path) const index = this.downloads.findIndex(download => download.path === path)
return this.downloads[index] || null return this.downloads[index] || null