From 1854059761db9a316b7675f03c1fe111bad04ab4 Mon Sep 17 00:00:00 2001 From: bossgeekgo Date: Wed, 14 Feb 2024 11:56:26 +0800 Subject: [PATCH] use initPuppeteer to check if it has import correct --- packages/geek-auto-start-chat-with-boss/index.mjs | 2 +- .../main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index 8f98572..b7b8e63 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -14,7 +14,7 @@ ensureConfigFileExist() const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE) let puppeteer, StealthPlugin -async function initPuppeteer () { +export async function initPuppeteer () { // production if ( isRunFromUi 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 631e57e..e569e59 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 @@ -1,4 +1,5 @@ import DingtalkPlugin from '@bossgeekgo/dingtalk-plugin/index.mjs' +import { app } from 'electron' import { SyncHook, AsyncSeriesHook @@ -11,13 +12,15 @@ const initPlugins = (hooks) => { } export const runAutoChat = async () => { - let mainLoop try { - mainLoop = (await import('@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs')).mainLoop + await (await import('@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs')).initPuppeteer() } catch { console.error(new Error('PUPPETEER_MAY_NOT_INSTALLED')) - process.exit(1) + app.exit(1) + return } + + const mainLoop = (await import('@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs')).mainLoop const hooks = { puppeteerLaunched: new SyncHook(), pageLoaded: new SyncHook(), @@ -33,7 +36,10 @@ export const runAutoChat = async () => { try { await mainLoop(hooks) } catch (err) { - void err + console.log(err) + if(err instanceof Error && err.message.includes('ERR_MODULE_NOT_FOUND')) { + throw err + } } } }