From 1ee8acd981cd07171b7ea64e11e18ca4ccd4519f Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Sun, 25 Feb 2024 14:03:32 +0800 Subject: [PATCH] remove console, and decrease the pipe write times for downloadProgressCallback, to solve the download process is badly block at a point on windows --- .../CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/ui/src/main/flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts b/packages/ui/src/main/flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts index e9f5ce5..73a0849 100644 --- a/packages/ui/src/main/flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts +++ b/packages/ui/src/main/flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts @@ -39,6 +39,7 @@ export const checkAndDownloadDependenciesForInit = async () => { return o })() + let throttleProgressTimer: number | null = null checkAndDownloadPuppeteerExecutable({ downloadProgressCallback(downloadedBytes: number, totalBytes: number) { clearTimeout(timeoutTimer) @@ -47,16 +48,30 @@ export const checkAndDownloadDependenciesForInit = async () => { // will encounter this when network disconnected when downloading promiseWithResolver.reject(new Error('PROGRESS_NOT_CHANGED_TOO_LONG')) }, 5 * 1000) + } else { + clearTimeout(throttleProgressTimer) + throttleProgressTimer = null + } + + if (!throttleProgressTimer) { + // console.log(JSON.stringify({ + // type: 'DOWNLOAD_PROGRESS_UPDATE', + // level: 'DEBUG', + // percent: downloadedBytes / totalBytes + // })) + + pipeWriteRegardlessError( + pipe, + JSON.stringify({ + type: 'PUPPETEER_DOWNLOAD_PROGRESS', + totalBytes, + downloadedBytes + }) + '\r\n' + ) + throttleProgressTimer = setTimeout(() => { + throttleProgressTimer = null + }, 2500) } - console.log(downloadedBytes / totalBytes) - pipeWriteRegardlessError( - pipe, - JSON.stringify({ - type: 'PUPPETEER_DOWNLOAD_PROGRESS', - totalBytes, - downloadedBytes - }) - ) + '\r\n' } }) .then(() => {