mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 15:44:35 +01:00
stop downloads when removed
This commit is contained in:
@@ -50,6 +50,11 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
|||||||
|
|
||||||
// Await chunks
|
// Await chunks
|
||||||
while let Some(item) = stream.next().await {
|
while let Some(item) = stream.next().await {
|
||||||
|
// Stop the loop if the download is removed from the list
|
||||||
|
if !DOWNLOADS.lock().unwrap().contains(&path.to_string()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
let chunk = match item {
|
let chunk = match item {
|
||||||
Ok(itm) => itm,
|
Ok(itm) => itm,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ async function download(url: string, filename: string, path: string) {
|
|||||||
|
|
||||||
async function TESTDOWNLOAD() {
|
async function TESTDOWNLOAD() {
|
||||||
download(
|
download(
|
||||||
'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/stable.zip',
|
'https://github.com/Koko-boya/Grasscutter_Resources/archive/refs/heads/main.zip',
|
||||||
'grasscutter.zip',
|
'resources.zip',
|
||||||
'S:\\Cultivation'
|
'S:\\Cultivation'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,13 +89,13 @@ export default class DownloadHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTotalAverage() {
|
getTotalAverage() {
|
||||||
const files = this.downloads.filter(d => d.status !== 'finished')
|
const files = this.downloads.filter(d => d.status === 'downloading')
|
||||||
const total = files.reduce((acc, d) => acc + d.total, 0)
|
const total = files.reduce((acc, d) => acc + d.total, 0)
|
||||||
const progress = files.reduce((acc, d) => acc + d.progress, 0)
|
const progress = files.reduce((acc, d) => acc + d.progress, 0)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
average: (progress / total) * 100 || 0,
|
average: (progress / total) * 100 || 0,
|
||||||
files: this.downloads.filter(d => d.status !== 'finished' && d.status !== 'error').length,
|
files: this.downloads.filter(d => d.status === 'downloading').length,
|
||||||
totalSize: total,
|
totalSize: total,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user