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(
'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/stable.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 './ProgressBar.css'
import DownloadHandler from '../../../utils/download'
interface IProps {
path: string,
downloadManager: any,
downloadManager: DownloadHandler,
}
interface IState {
@@ -31,7 +32,7 @@ export default class ProgressBar extends React.Component<IProps, IState> {
const intv = setInterval(() => {
const prog = this.props.downloadManager.getDownloadProgress(this.props.path)
this.setState({
progress: parseInt(prog?.progress || 0, 10),
progress: prog?.progress || 0,
status: prog?.status || 'error',
total: prog?.total || 0,
})
@@ -43,6 +44,10 @@ export default class ProgressBar extends React.Component<IProps, IState> {
}, 500)
}
stopDownload() {
this.props.downloadManager.stopDownload(this.props.path)
}
render() {
return (
<div className="ProgressBarWrapper">
@@ -66,7 +71,7 @@ export default class ProgressBar extends React.Component<IProps, IState> {
}}></div>
</div>
<div className="DownloadControls">
<div>
<div onClick={this.stopDownload}>
<img src={Stop}></img>
</div>
</div>

View File

@@ -69,6 +69,15 @@ export default class DownloadHandler {
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) {
const index = this.downloads.findIndex(download => download.path === path)
return this.downloads[index] || null