mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-20 00:41:48 +03:00
added auto-changing between GB, MB, KB.. in progress bar
This commit is contained in:
parent
0240b282f2
commit
f401a52be1
2 changed files with 28 additions and 2 deletions
|
@ -183,7 +183,7 @@ export default class LauncherUI
|
|||
|
||||
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;
|
||||
|
||||
|
@ -208,7 +208,7 @@ export default class LauncherUI
|
|||
etaSeconds = '0' + etaSeconds.toString();
|
||||
|
||||
$('#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}`);
|
||||
|
||||
this.progressBar.prevTime = Date.now();
|
||||
|
|
|
@ -24,6 +24,32 @@ type Pixel = {
|
|||
|
||||
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[]>
|
||||
{
|
||||
return new Promise(resolve => {
|
||||
|
|
Loading…
Reference in a new issue