diff --git a/packages/ui/electron.vite.config.ts b/packages/ui/electron.vite.config.ts index bae286f..adb4d26 100644 --- a/packages/ui/electron.vite.config.ts +++ b/packages/ui/electron.vite.config.ts @@ -4,7 +4,16 @@ import vue from '@vitejs/plugin-vue' export default defineConfig({ main: { - plugins: [externalizeDepsPlugin({ exclude: ['@bossgeekgo/geek-auto-start-chat-with-boss', '@bossgeekgo/dingtalk-plugin'] })] + build: { + rollupOptions: { + external: ['puppeteer', 'puppeteer-extra', 'puppeteer-extra-plugin-stealth'] + } + }, + plugins: [ + externalizeDepsPlugin({ + exclude: ['@bossgeekgo/geek-auto-start-chat-with-boss', '@bossgeekgo/dingtalk-plugin'] + }) + ] }, preload: { plugins: [externalizeDepsPlugin()] 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 10054a0..631e57e 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,5 +1,4 @@ import DingtalkPlugin from '@bossgeekgo/dingtalk-plugin/index.mjs' -import { mainLoop } from '@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs' import { SyncHook, AsyncSeriesHook @@ -12,6 +11,13 @@ const initPlugins = (hooks) => { } export const runAutoChat = async () => { + let mainLoop + try { + mainLoop = (await import('@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs')).mainLoop + } catch { + console.error(new Error('PUPPETEER_MAY_NOT_INSTALLED')) + process.exit(1) + } const hooks = { puppeteerLaunched: new SyncHook(), pageLoaded: new SyncHook(), diff --git a/packages/ui/src/main/window/mainWindow.ts b/packages/ui/src/main/window/mainWindow.ts index f5aa855..17c1cae 100644 --- a/packages/ui/src/main/window/mainWindow.ts +++ b/packages/ui/src/main/window/mainWindow.ts @@ -85,6 +85,12 @@ export function createMainWindow(): void { if (subProcessOfPuppeteer) { return } + try { + await import('@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs') + } catch (err){ + console.log(err) // TODO: what's the error? + throw new Error('PUPPETEER_MAY_NOT_INSTALLED') + } console.log(process) subProcessOfPuppeteer = childProcess.spawn(process.argv[0], process.argv.slice(1), { env: { diff --git a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue index 21d6c8e..eb8200e 100644 --- a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue +++ b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue @@ -78,7 +78,12 @@ const formRef = ref>() const handleSubmit = async () => { await formRef.value!.validate() await electron.ipcRenderer.invoke('save-config-file-from-ui', JSON.stringify(formContent.value)) - await electron.ipcRenderer.invoke('run-geek-auto-start-chat-with-boss', JSON.stringify(formContent.value)) + try { + await electron.ipcRenderer.invoke('run-geek-auto-start-chat-with-boss', JSON.stringify(formContent.value)) + } catch (err) { + console.log(err) + return + } router.replace('/geekAutoStartChatWithBoss/runningStatus') } const handleSave = async () => {