remove useless ipc channel in GEEK_AUTO_START_CHAT_WITH_BOSS.ts - it only response for auto chat, not include download puppeteer

This commit is contained in:
bossgeekgo
2024-02-17 19:36:38 +08:00
parent 294213c442
commit 4a86b57f57
3 changed files with 3 additions and 81 deletions

View File

@@ -5,10 +5,7 @@ import { readConfigFile } from '@bossgeekgo/geek-auto-start-chat-with-boss/runti
import * as net from 'net'
import {
checkPuppeteerExecutable,
getExpectPuppeteerExecutablePath
} from './CHECK_AND_DOWNLOAD_DEPENDENCIES/check-and-download-puppeteer'
import * as childProcess from 'node:child_process'
import * as JSONStream from 'JSONStream'
const { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk.json')
@@ -36,67 +33,14 @@ export const runAutoChat = async () => {
}) + '\r\n'
)
} catch {
console.error(new Error('PUPPETEER_MAY_NOT_INSTALLED'))
pipe?.write(
JSON.stringify({
type: 'PUPPETEER_MAY_NOT_INSTALLED'
}) + '\r\n'
)
app.exit(1)
return
}
const isPuppeteerExecutable = await checkPuppeteerExecutable()
if (!isPuppeteerExecutable) {
const subProcessEnv = {
...process.env,
MAIN_BOSSGEEKGO_UI_RUN_MODE: 'checkAndDownloadDependenciesForInit',
PUPPETEER_EXECUTABLE_PATH: await getExpectPuppeteerExecutablePath()
}
const subProcessOfCheckAndDownloadDependencies = childProcess.spawn(
process.argv[0],
process.argv.slice(1),
{
env: subProcessEnv,
stdio: [null, null, null, 'pipe']
}
)
await new Promise((resolve) => {
subProcessOfCheckAndDownloadDependencies!.stdio[3]!.pipe(JSONStream.parse()).on(
'data',
(raw) => {
const data = raw
switch (data.type) {
case 'NEED_RESETUP_DEPENDENCIES':
case 'PUPPETEER_DOWNLOAD_PROGRESS': {
pipe?.write(JSON.stringify(data) + '\r\n')
break
}
case 'PUPPETEER_DOWNLOAD_FINISHED': {
subProcessOfCheckAndDownloadDependencies?.kill()
pipe?.write(JSON.stringify(data) + '\r\n')
resolve(data)
break
}
case 'PUPPETEER_DOWNLOAD_ERROR': {
subProcessOfCheckAndDownloadDependencies?.kill()
pipe?.write(JSON.stringify(data) + '\r\n')
resolve(data)
break
}
case 'PUPPETEER_MAY_NOT_INSTALLED': {
pipe?.write(JSON.stringify(data) + '\r\n')
resolve(data)
break
}
default: {
return
}
}
}
)
})
app.exit(1)
return
}
const mainLoop = (await import('@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs')).mainLoop

View File

@@ -111,17 +111,10 @@ export function createMainWindow(): void {
subProcessOfPuppeteer!.stdio[3]!.pipe(JSONStream.parse()).on('data', (raw) => {
const data = raw
switch (data.type) {
case 'GEEK_AUTO_START_CHAT_WITH_BOSS_STARTED':
case 'PUPPETEER_MAY_NOT_INSTALLED': {
case 'GEEK_AUTO_START_CHAT_WITH_BOSS_STARTED': {
resolve(data)
break
}
case 'NEED_RESETUP_DEPENDENCIES':
case 'PUPPETEER_DOWNLOAD_FINISHED':
case 'PUPPETEER_DOWNLOAD_PROGRESS': {
mainWindow.webContents.send(data.type, data)
break
}
default: {
return
}

View File

@@ -85,21 +85,6 @@ const handleSubmit = async () => {
if (res.type === 'GEEK_AUTO_START_CHAT_WITH_BOSS_STARTED') {
router.replace('/geekAutoStartChatWithBoss/runningStatus')
} else if (res.type === 'PUPPETEER_MAY_NOT_INSTALLED') {
ElMessageBox.confirm(
'Some core components is broken, please reinstall this program. Will you go to the download page?',
'Error',
{
confirmButtonText: 'OK',
cancelButtonText: 'Cancel',
type: 'error'
}
)
.then(() => {
electron.ipcRenderer.emit('open-project-homepage-on-github')
})
.catch(() => {})
return
}
}
const handleSave = async () => {