From 5bd84716ed6efe41a183c4ae3db364e2c49fa9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sun, 24 Jan 2021 16:13:33 +0200 Subject: Code: reduce progress notification spam --- editors/code/src/net.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index 1ab21e726..3e50d352c 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts @@ -99,13 +99,15 @@ export async function download(opts: DownloadOpts) { async (progress, _cancellationToken) => { let lastPercentage = 0; await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => { - const newPercentage = (readBytes / totalBytes) * 100; - progress.report({ - message: newPercentage.toFixed(0) + "%", - increment: newPercentage - lastPercentage - }); - - lastPercentage = newPercentage; + const newPercentage = Math.round((readBytes / totalBytes) * 100); + if (newPercentage !== lastPercentage) { + progress.report({ + message: `${newPercentage.toFixed(0)}%`, + increment: newPercentage - lastPercentage + }); + + lastPercentage = newPercentage; + } }); } ); -- cgit v1.2.3