add check dependencies logic before automatic start

This commit is contained in:
bossgeekgo
2024-02-17 21:39:35 +08:00
parent 4a86b57f57
commit 5ede58169d
2 changed files with 34 additions and 13 deletions
+11 -6
View File
@@ -101,13 +101,8 @@ export function createMainWindow(): void {
env: subProcessEnv, env: subProcessEnv,
stdio: [null, null, null, 'pipe'] stdio: [null, null, null, 'pipe']
}) })
subProcessOfPuppeteer.once('exit', () => {
mainWindow.webContents.send('geek-auto-start-chat-with-boss-stopped')
subProcessOfPuppeteer = null
})
console.log(subProcessOfPuppeteer) console.log(subProcessOfPuppeteer)
return new Promise((resolve) => { return new Promise((resolve, reject) => {
subProcessOfPuppeteer!.stdio[3]!.pipe(JSONStream.parse()).on('data', (raw) => { subProcessOfPuppeteer!.stdio[3]!.pipe(JSONStream.parse()).on('data', (raw) => {
const data = raw const data = raw
switch (data.type) { switch (data.type) {
@@ -120,6 +115,16 @@ export function createMainWindow(): void {
} }
} }
}) })
subProcessOfPuppeteer!.once('exit', (exitCode) => {
subProcessOfPuppeteer = null
if (exitCode === 1) {
// means cannot find downloaded puppeteer
reject('NEED_TO_CHECK_RUNTIME_DEPENDENCIES')
} else {
mainWindow.webContents.send('geek-auto-start-chat-with-boss-stopped')
}
})
}) })
// TODO: // TODO:
}) })
@@ -33,8 +33,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { ref } from 'vue'
import JSON5 from 'json5' import JSON5 from 'json5'
import { ElForm, ElMessage, ElMessageBox } from 'element-plus' import { ElForm, ElMessage } from 'element-plus'
import router from '../../router/index' import router from '../../router/index'
import { mountGlobalDialog as mountDependenciesSetupProgressIndicatorDialog } from '@renderer/features/DependenciesSetupProgressIndicatorDialog/operations'
const formContent = ref({ const formContent = ref({
bossZhipinCookies: '', bossZhipinCookies: '',
@@ -78,13 +79,28 @@ const formRef = ref<InstanceType<typeof ElForm>>()
const handleSubmit = async () => { const handleSubmit = async () => {
await formRef.value!.validate() await formRef.value!.validate()
await electron.ipcRenderer.invoke('save-config-file-from-ui', JSON.stringify(formContent.value)) await electron.ipcRenderer.invoke('save-config-file-from-ui', JSON.stringify(formContent.value))
const res = await electron.ipcRenderer.invoke(
'run-geek-auto-start-chat-with-boss',
JSON.stringify(formContent.value)
)
if (res.type === 'GEEK_AUTO_START_CHAT_WITH_BOSS_STARTED') { try {
router.replace('/geekAutoStartChatWithBoss/runningStatus') const res = await electron.ipcRenderer.invoke(
'run-geek-auto-start-chat-with-boss',
JSON.stringify(formContent.value)
)
if (res.type === 'GEEK_AUTO_START_CHAT_WITH_BOSS_STARTED') {
router.replace('/geekAutoStartChatWithBoss/runningStatus')
}
} catch (err) {
if (err instanceof Error && err.message.includes('NEED_TO_CHECK_RUNTIME_DEPENDENCIES')) {
ElMessage.error({
message: `Some dependencies might be corrupt. I'm trying to check and fix them.`
})
const checkDependenciesResult = await electron.ipcRenderer.invoke('check-dependencies')
if (!checkDependenciesResult) {
mountDependenciesSetupProgressIndicatorDialog()
// TODO: should continue interrupted task
}
}
console.error(err)
} }
} }
const handleSave = async () => { const handleSave = async () => {