added auto-changing between GB, MB, KB.. in progress bar

This commit is contained in:
Observer KRypt0n_ 2021-11-26 21:32:06 +02:00
parent 0240b282f2
commit f401a52be1
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
2 changed files with 28 additions and 2 deletions

View file

@ -183,7 +183,7 @@ export default class LauncherUI
public static updateProgressBar (prefix: string, current: number, total: number, difference: number): void public static updateProgressBar (prefix: string, current: number, total: number, difference: number): void
{ {
$('#downloaded').text(`${prefix}: ${ Math.round(current / total * 100) }% (${ (current / 1024 / 1024 / 1024).toFixed(2) } GB / ${ Math.round(total / 1024 / 1024 / 1024).toFixed(2) } GB)`); $('#downloaded').text(`${prefix}: ${ Math.round(current / total * 100) }% (${Tools.prettifyBytes(current)} / ${Tools.prettifyBytes(total)})`);
this.progressBar.temp += difference; this.progressBar.temp += difference;
@ -208,7 +208,7 @@ export default class LauncherUI
etaSeconds = '0' + etaSeconds.toString(); etaSeconds = '0' + etaSeconds.toString();
$('#downloader .progress').css('width', `${ Math.round(current / total * 100) }%`); $('#downloader .progress').css('width', `${ Math.round(current / total * 100) }%`);
$('#speed').text(`${ (this.progressBar.temp / (Date.now() - this.progressBar.prevTime) * 1000 / 1024 / 1024).toFixed(2) } MB/s`); $('#speed').text(`${Tools.prettifyBytes(this.progressBar.temp / (Date.now() - this.progressBar.prevTime) * 1000)}/s`);
$('#eta').text(`ETA: ${etaHours}:${etaMinutes}:${etaSeconds}`); $('#eta').text(`ETA: ${etaHours}:${etaMinutes}:${etaSeconds}`);
this.progressBar.prevTime = Date.now(); this.progressBar.prevTime = Date.now();

View file

@ -24,6 +24,32 @@ type Pixel = {
export default class Tools export default class Tools
{ {
public static prettifyBytes (bytes: number): string
{
const types = [
{
name: 'B',
multiplier: 1
},
{
name: 'KB',
multiplier: 1024
},
{
name: 'MB',
multiplier: 1024 * 1024
},
{
name: 'GB',
multiplier: 1024 * 1024 * 1024
}
].filter(type => type.multiplier < bytes);
return types.length == 0 ?
`${bytes} B` :
`${(bytes / types[types.length - 1].multiplier).toFixed(2)} ${types[types.length - 1].name}`;
}
public static getImagePixels (path: string): Promise<Pixel[]> public static getImagePixels (path: string): Promise<Pixel[]>
{ {
return new Promise(resolve => { return new Promise(resolve => {