mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 16:14:48 +01:00
download stop button
This commit is contained in:
@@ -13,7 +13,7 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
|||||||
let res = match reqwest::get(url)
|
let res = match reqwest::get(url)
|
||||||
.await {
|
.await {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => {
|
Err(_e) => {
|
||||||
emit_download_err(window, format!("Failed to request {}", url), url);
|
emit_download_err(window, format!("Failed to request {}", url), url);
|
||||||
return Err(format!("Failed to request {}", url));
|
return Err(format!("Failed to request {}", url));
|
||||||
},
|
},
|
||||||
@@ -25,7 +25,7 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
|||||||
// Create file path
|
// Create file path
|
||||||
let mut file = match File::create(path) {
|
let mut file = match File::create(path) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(_e) => {
|
||||||
emit_download_err(window, format!("Failed to create file '{}'", path), path);
|
emit_download_err(window, format!("Failed to create file '{}'", path), path);
|
||||||
return Err(format!("Failed to create file '{}'", path));
|
return Err(format!("Failed to create file '{}'", path));
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
font-family: 'Helvetica Neue', BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans',
|
||||||
sans-serif;
|
sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
|||||||
@@ -34,5 +34,6 @@ body {
|
|||||||
#DownloadProgress {
|
#DownloadProgress {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 85%;
|
top: 85%;
|
||||||
|
left: 5%;
|
||||||
width: 60%;
|
width: 60%;
|
||||||
}
|
}
|
||||||
@@ -12,5 +12,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#serverControls .Checkbox label {
|
#serverControls .Checkbox label {
|
||||||
color: #000;
|
color: #fff;
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import DownloadHandler from '../../../utils/download'
|
||||||
import './ProgressBar.css'
|
import './ProgressBar.css'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
downloadManager: any,
|
downloadManager: DownloadHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
@@ -18,12 +19,12 @@ export default class ProgressBar extends React.Component<IProps, IState> {
|
|||||||
constructor(props: IProps) {
|
constructor(props: IProps) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
const { average, files, total } = this.props.downloadManager.getTotalAverage()
|
const { average, files, totalSize } = this.props.downloadManager.getTotalAverage()
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
average,
|
average,
|
||||||
files,
|
files,
|
||||||
total
|
total: totalSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ export default class ProgressBar extends React.Component<IProps, IState> {
|
|||||||
const intv = setInterval(() => {
|
const intv = setInterval(() => {
|
||||||
const prog = this.props.downloadManager.getTotalAverage()
|
const prog = this.props.downloadManager.getTotalAverage()
|
||||||
this.setState({
|
this.setState({
|
||||||
average: parseInt(prog?.average || 0, 10),
|
average: prog?.average || 0,
|
||||||
files: prog?.files,
|
files: prog?.files,
|
||||||
total: prog?.totalSize || 0,
|
total: prog?.totalSize || 0,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
.InnerProgress {
|
.InnerProgress {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-color: #ffc61e;
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ProgressText {
|
.ProgressText {
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
.MainProgressBarWrapper {
|
.MainProgressBarWrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: flex-start;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
color: #fff;
|
color: #fff;
|
||||||
@@ -40,4 +40,28 @@
|
|||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #fff !important;
|
color: #fff !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ProgressBarWrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.DownloadControls {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.DownloadControls div {
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.DownloadControls div img {
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { capitalize } from '../../../utils/string'
|
import { capitalize } from '../../../utils/string'
|
||||||
|
|
||||||
|
import Stop from '../../../resources/icons/close.svg'
|
||||||
import './ProgressBar.css'
|
import './ProgressBar.css'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
@@ -45,23 +46,31 @@ export default class ProgressBar extends React.Component<IProps, IState> {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="ProgressBarWrapper">
|
<div className="ProgressBarWrapper">
|
||||||
<div className="ProgressBar">
|
<div>
|
||||||
<div className="InnerProgress" style={{
|
<div className="ProgressBar">
|
||||||
width: `${(() => {
|
<div className="InnerProgress" style={{
|
||||||
// Handles files with content-lengths of 0
|
width: `${(() => {
|
||||||
if (this.state.status === 'finished') {
|
// Handles files with content-lengths of 0
|
||||||
return '100'
|
if (this.state.status === 'finished') {
|
||||||
}
|
return '100'
|
||||||
|
}
|
||||||
|
|
||||||
if (this.state.total <= 0) {
|
if (this.state.total <= 0) {
|
||||||
return '0'
|
return '0'
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.state.progress / this.state.total * 100
|
return this.state.progress / this.state.total * 100
|
||||||
})()}%`,
|
})()}%`,
|
||||||
}}></div>
|
}}></div>
|
||||||
|
</div>
|
||||||
|
<div className="DownloadControls">
|
||||||
|
<div>
|
||||||
|
<img src={Stop}></img>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div className="ProgressText">
|
<div className="ProgressText">
|
||||||
{capitalize(this.state.status)}
|
{capitalize(this.state.status)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export default class DownloadHandler {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
average: (progress / total) * 100 || 0,
|
average: (progress / total) * 100 || 0,
|
||||||
files: this.downloads.filter(d => d.status !== 'finished').length,
|
files: this.downloads.filter(d => d.status !== 'finished' && d.status !== 'error').length,
|
||||||
totalSize: total,
|
totalSize: total,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user