From 294213c44214db32f25d00f4350fa9ee7a292c9f Mon Sep 17 00:00:00 2001 From: bossgeekgo Date: Sat, 17 Feb 2024 19:08:17 +0800 Subject: [PATCH] handle download process of puppeteer not change to long (will encounter this when network disconnected when downloading) --- .../CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 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 94090db..a624dbb 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 @@ -21,16 +21,34 @@ export const checkAndDownloadDependenciesForInit = async () => { ) try { - await checkAndDownloadPuppeteer({ - downloadProgressCallback(downloadedBytes: number, totalBytes: number) { - pipe?.write( - JSON.stringify({ - type: 'PUPPETEER_DOWNLOAD_PROGRESS', - totalBytes, - downloadedBytes - }) - ) + '\r\n' - } + let timeoutTimer = 0 + await new Promise((resolve, reject) => { + checkAndDownloadPuppeteer({ + downloadProgressCallback(downloadedBytes: number, totalBytes: number) { + clearTimeout(timeoutTimer) + if (downloadedBytes !== totalBytes) { + timeoutTimer = setTimeout(() => { + // will encounter this when network disconnected when downloading + reject(new Error('PROGRESS_NOT_CHANGED_TOO_LONG')) + }, 30 * 1000) + } + console.log(downloadedBytes / totalBytes) + pipe?.write( + JSON.stringify({ + type: 'PUPPETEER_DOWNLOAD_PROGRESS', + totalBytes, + downloadedBytes + }) + ) + '\r\n' + } + }).then( + () => { + resolve(void 0) + }, + (err) => { + reject(err) + } + ) }) app.exit(DOWNLOAD_ERROR_EXIT_CODE.NO_ERROR) } catch (err) {