mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2026-02-04 09:25:16 +01:00
improve downloads dialog
This commit is contained in:
@@ -17,7 +17,7 @@ export default class MiniDialog extends React.Component<IProps, never> {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="DownloadSection">
|
<div className="DownloadSection">
|
||||||
<span>{this.props.downloadName}</span>
|
<span>{this.props.downloadName} - {this.props.downloadManager.getDownloadSize(this.props.downloadName)}</span>
|
||||||
<div className="DownloadSectionInner">
|
<div className="DownloadSectionInner">
|
||||||
<ProgressBar path={this.props.downloadName} downloadManager={this.props.downloadManager} />
|
<ProgressBar path={this.props.downloadName} downloadManager={this.props.downloadManager} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import { invoke } from '@tauri-apps/api/tauri'
|
import { invoke } from '@tauri-apps/api/tauri'
|
||||||
import { listen } from '@tauri-apps/api/event'
|
import { listen } from '@tauri-apps/api/event'
|
||||||
|
import { byteToString } from './string'
|
||||||
|
|
||||||
export default class DownloadHandler {
|
export default class DownloadHandler {
|
||||||
downloads: {
|
downloads: {
|
||||||
@@ -73,6 +74,11 @@ export default class DownloadHandler {
|
|||||||
return this.downloads[index] || null
|
return this.downloads[index] || null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDownloadSize(path: string) {
|
||||||
|
const index = this.downloads.findIndex(download => download.path === path)
|
||||||
|
return byteToString(this.downloads[index].total) || null
|
||||||
|
}
|
||||||
|
|
||||||
getTotalAverage() {
|
getTotalAverage() {
|
||||||
const files = this.downloads.filter(d => d.status !== 'finished')
|
const files = this.downloads.filter(d => d.status !== 'finished')
|
||||||
const total = files.reduce((acc, d) => acc + d.total, 0)
|
const total = files.reduce((acc, d) => acc + d.total, 0)
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
export function capitalize(str: string) {
|
export function capitalize(str: string) {
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1)
|
return str.charAt(0).toUpperCase() + str.slice(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function byteToString(bytes: number) {
|
||||||
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
|
||||||
|
if (bytes === 0) return '0 Bytes'
|
||||||
|
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString(), 10)
|
||||||
|
if (i === 0) return `${bytes} ${sizes[i]}`
|
||||||
|
return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${sizes[i]}`
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user