mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-30 12:39:58 +08:00
migrate the logic of check dependencies to on app launch
This commit is contained in:
@@ -9,7 +9,10 @@ import {
|
||||
writeConfigFile
|
||||
} from '@bossgeekgo/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||
import { ChildProcess } from 'child_process'
|
||||
import { getExpectPuppeteerExecutablePath } from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/check-and-download-puppeteer'
|
||||
import {
|
||||
checkPuppeteerExecutable,
|
||||
getExpectPuppeteerExecutablePath
|
||||
} from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/check-and-download-puppeteer'
|
||||
import * as JSONStream from 'JSONStream'
|
||||
let mainWindow: BrowserWindow
|
||||
|
||||
@@ -22,8 +25,8 @@ export function createMainWindow(): void {
|
||||
autoHideMenuBar: true,
|
||||
...(process.platform === 'linux'
|
||||
? {
|
||||
/* icon */
|
||||
}
|
||||
/* icon */
|
||||
}
|
||||
: {}),
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, '../preload/index.js'),
|
||||
@@ -126,6 +129,65 @@ export function createMainWindow(): void {
|
||||
})
|
||||
// TODO:
|
||||
})
|
||||
|
||||
ipcMain.handle('check-dependencies', async () => {
|
||||
return await checkPuppeteerExecutable()
|
||||
})
|
||||
|
||||
let subProcessOfCheckAndDownloadDependencies: ChildProcess
|
||||
ipcMain.handle('setup-dependencies', async () => {
|
||||
if (subProcessOfCheckAndDownloadDependencies) {
|
||||
return
|
||||
}
|
||||
const subProcessEnv = {
|
||||
...process.env,
|
||||
MAIN_BOSSGEEKGO_UI_RUN_MODE: 'checkAndDownloadDependenciesForInit',
|
||||
PUPPETEER_EXECUTABLE_PATH: await getExpectPuppeteerExecutablePath()
|
||||
}
|
||||
subProcessOfCheckAndDownloadDependencies = childProcess.spawn(
|
||||
process.argv[0],
|
||||
process.argv.slice(1),
|
||||
{
|
||||
env: subProcessEnv,
|
||||
stdio: [null, null, null, 'pipe']
|
||||
}
|
||||
)
|
||||
return new Promise((resolve) => {
|
||||
subProcessOfCheckAndDownloadDependencies!.stdio[3]!.pipe(JSONStream.parse()).on(
|
||||
'data',
|
||||
(raw) => {
|
||||
const data = raw
|
||||
switch (data.type) {
|
||||
case 'PUPPETEER_DOWNLOAD_FINISHED': {
|
||||
mainWindow.webContents.send(data.type, data)
|
||||
resolve(data)
|
||||
break
|
||||
}
|
||||
case 'NEED_RESETUP_DEPENDENCIES':
|
||||
case 'PUPPETEER_DOWNLOAD_PROGRESS': {
|
||||
mainWindow.webContents.send(data.type, data)
|
||||
break
|
||||
}
|
||||
default: {
|
||||
return
|
||||
}
|
||||
// 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
|
||||
// }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
ipcMain.handle('stop-geek-auto-start-chat-with-boss', async () => {
|
||||
mainWindow.webContents.send('geek-auto-start-chat-with-boss-stopping')
|
||||
subProcessOfPuppeteer?.kill('SIGINT')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<el-dialog v-bind="$attrs" @open="percentage = 0">
|
||||
<div>Downloading the necessary dependencies...</div>
|
||||
<el-progress :percentage="percentage" :format="(n) => `${n.toFixed(1)}%`" />
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
@@ -31,11 +31,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onUnmounted, ref } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import JSON5 from 'json5'
|
||||
import { ElForm, ElMessage, ElMessageBox } from 'element-plus'
|
||||
import router from '../../router/index'
|
||||
import { mountGlobalDialog as mountDependenciesSetupProgressIndicatorDialog } from '@renderer/features/DependenciesSetupProgressIndicatorDialog/operations'
|
||||
|
||||
const formContent = ref({
|
||||
bossZhipinCookies: '',
|
||||
@@ -116,19 +115,6 @@ const handleExpectCompaniesInputBlur = (event) => {
|
||||
.filter(Boolean)
|
||||
.join(',')
|
||||
}
|
||||
|
||||
const needWarmingUpDenpendenciesHandler = () => {
|
||||
const processDialog = mountDependenciesSetupProgressIndicatorDialog()
|
||||
|
||||
const handlePuppeteerDownloadFinished = () => {
|
||||
processDialog?.dispose()
|
||||
}
|
||||
electron.ipcRenderer.once('PUPPETEER_DOWNLOAD_FINISHED', handlePuppeteerDownloadFinished)
|
||||
}
|
||||
electron.ipcRenderer.on('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler)
|
||||
onUnmounted(
|
||||
() => electron.ipcRenderer.removeListener('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler)
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -1 +1,44 @@
|
||||
<template><RouterView /></template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onUnmounted } from 'vue'
|
||||
import { mountGlobalDialog as mountDependenciesSetupProgressIndicatorDialog } from '@renderer/features/DependenciesSetupProgressIndicatorDialog/operations'
|
||||
|
||||
const unmountedCbs: Array<InstanceType<typeof Function>> = []
|
||||
onUnmounted(() => {
|
||||
while (unmountedCbs.length) {
|
||||
const fn = unmountedCbs.shift()!
|
||||
try {
|
||||
fn()
|
||||
} catch {}
|
||||
}
|
||||
})
|
||||
;(async () => {
|
||||
const checkDependenciesResult = await electron.ipcRenderer.invoke('check-dependencies')
|
||||
if (!checkDependenciesResult) {
|
||||
let processDialog
|
||||
const needWarmingUpDenpendenciesHandler = () => {
|
||||
processDialog = mountDependenciesSetupProgressIndicatorDialog()
|
||||
}
|
||||
electron.ipcRenderer.on('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler)
|
||||
|
||||
const handlePuppeteerDownloadFinished = () => {
|
||||
processDialog?.dispose()
|
||||
}
|
||||
electron.ipcRenderer.once('PUPPETEER_DOWNLOAD_FINISHED', handlePuppeteerDownloadFinished)
|
||||
|
||||
unmountedCbs.push(
|
||||
() => {
|
||||
electron.ipcRenderer.removeListener('PUPPETEER_DOWNLOAD_FINISHED', handlePuppeteerDownloadFinished)
|
||||
electron.ipcRenderer.removeListener('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler)
|
||||
}
|
||||
)
|
||||
try {
|
||||
await electron.ipcRenderer.invoke('setup-dependencies')
|
||||
} finally {
|
||||
electron.ipcRenderer.removeListener('PUPPETEER_DOWNLOAD_FINISHED', handlePuppeteerDownloadFinished)
|
||||
electron.ipcRenderer.removeListener('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler)
|
||||
}
|
||||
}
|
||||
})()
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user