set puppeteer dependencies as external; check if the puppeteer installed before run.

This commit is contained in:
bossgeekgo
2024-02-13 13:05:34 +08:00
parent 6cf550bf8d
commit 79d1580382
4 changed files with 29 additions and 3 deletions

View File

@@ -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()]

View File

@@ -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(),

View File

@@ -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: {

View File

@@ -78,7 +78,12 @@ const formRef = ref<InstanceType<typeof ElForm>>()
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 () => {