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 8d9a2c7..937bfd5 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 @@ -15,17 +15,31 @@ export const checkAndDownloadDependenciesForInit = async () => { }) + '\r\n' ) - const browser = await checkAndDownloadPuppeteer({ - downloadProgressCallback(downloadedBytes: number, totalBytes: number) { - pipe?.write( - JSON.stringify({ - type: 'PUPPETEER_DOWNLOAD_PROGRESS', - totalBytes, - downloadedBytes - }) - ) + '\r\n' - } - }) + let browser + try { + browser = await checkAndDownloadPuppeteer({ + downloadProgressCallback(downloadedBytes: number, totalBytes: number) { + pipe?.write( + JSON.stringify({ + type: 'PUPPETEER_DOWNLOAD_PROGRESS', + totalBytes, + downloadedBytes + }) + ) + '\r\n' + } + }) + pipe?.write( + JSON.stringify({ + type: 'PUPPETEER_DOWNLOAD_FINISHED' + }) + ) + '\r\n' + } catch (err) { + pipe?.write( + JSON.stringify({ + type: 'PUPPETEER_DOWNLOAD_ERROR' + }) + ) + '\r\n' + } console.log(browser) } diff --git a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS.ts b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS.ts index 1694e27..7c41757 100644 --- a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS.ts +++ b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS.ts @@ -68,10 +68,9 @@ export const runAutoChat = async () => { (raw) => { const data = raw switch (data.type) { - case 'NEED_RESETUP_DEPENDENCIES': { - pipe?.write(JSON.stringify(data) + '\r\n') - break - } + case 'NEED_RESETUP_DEPENDENCIES': + case 'PUPPETEER_DOWNLOAD_ERROR': + case 'PUPPETEER_DOWNLOAD_FINISHED': case 'PUPPETEER_DOWNLOAD_PROGRESS': { pipe?.write(JSON.stringify(data) + '\r\n') break diff --git a/packages/ui/src/main/window/mainWindow.ts b/packages/ui/src/main/window/mainWindow.ts index e072e1a..48fa0e9 100644 --- a/packages/ui/src/main/window/mainWindow.ts +++ b/packages/ui/src/main/window/mainWindow.ts @@ -112,12 +112,10 @@ export function createMainWindow(): void { resolve(data) break } - case 'NEED_RESETUP_DEPENDENCIES': { - mainWindow.webContents.send('NEED_RESETUP_DEPENDENCIES', data) - break - } + case 'NEED_RESETUP_DEPENDENCIES': + case 'PUPPETEER_DOWNLOAD_FINISHED': case 'PUPPETEER_DOWNLOAD_PROGRESS': { - mainWindow.webContents.send('PUPPETEER_DOWNLOAD_PROGRESS', data) + mainWindow.webContents.send(data.type, data) break } default: { diff --git a/packages/ui/src/renderer/src/features/DependenciesWarmingUpDialog.vue b/packages/ui/src/renderer/src/features/DependenciesWarmingUpDialog.vue index 68cf5fc..7a5c6ce 100644 --- a/packages/ui/src/renderer/src/features/DependenciesWarmingUpDialog.vue +++ b/packages/ui/src/renderer/src/features/DependenciesWarmingUpDialog.vue @@ -13,6 +13,6 @@ const handleProgress = (ev, { downloadedBytes, totalBytes }) => { } electron.ipcRenderer.on('PUPPETEER_DOWNLOAD_PROGRESS', handleProgress) onUnmounted( - () => electron.ipcRenderer.off('PUPPETEER_DOWNLOAD_PROGRESS', handleProgress) + () => electron.ipcRenderer.removeListener('PUPPETEER_DOWNLOAD_PROGRESS', handleProgress) ) diff --git a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue index 3ce1109..3cf72fa 100644 --- a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue +++ b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue @@ -122,10 +122,15 @@ const shouldShowDependenciesWarmingUpDialog = ref(false) const needWarmingUpDenpendenciesHandler = () => { shouldShowDependenciesWarmingUpDialog.value = true + + const handlePuppeteerDownloadFinished = () => { + shouldShowDependenciesWarmingUpDialog.value = false + } + electron.ipcRenderer.once('PUPPETEER_DOWNLOAD_FINISHED', handlePuppeteerDownloadFinished) } -electron.ipcRenderer.on('NEED_CONFIGURATE_DEPENDENCIES', needWarmingUpDenpendenciesHandler) +electron.ipcRenderer.on('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler) onUnmounted( - () => electron.ipcRenderer.off('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler) + () => electron.ipcRenderer.removeListener('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler) )