From 275138a8857bc45134593cf2701beacd7200780a Mon Sep 17 00:00:00 2001 From: bossgeekgo Date: Mon, 12 Feb 2024 17:41:25 +0800 Subject: [PATCH] add logic that launch auto start chat from render process --- packages/ui/src/main/window/mainWindow.ts | 17 +++++++++++++++++ .../Configuration/GeekAutoStartChatWithBoss.vue | 1 + 2 files changed, 18 insertions(+) diff --git a/packages/ui/src/main/window/mainWindow.ts b/packages/ui/src/main/window/mainWindow.ts index 0aa661d..783f1b3 100644 --- a/packages/ui/src/main/window/mainWindow.ts +++ b/packages/ui/src/main/window/mainWindow.ts @@ -1,5 +1,6 @@ import { BrowserWindow, ipcMain, shell } from 'electron' import path from 'path' +import * as childProcess from 'node:child_process' import { is } from '@electron-toolkit/utils' import { readConfigFile, @@ -7,6 +8,7 @@ import { ensureConfigFileExist, writeConfigFile } from '@bossgeekgo/geek-auto-start-chat-with-boss/runtime-file-utils.mjs' +import { ChildProcess } from 'child_process' let mainWindow: BrowserWindow export function createMainWindow(): void { @@ -74,4 +76,19 @@ export function createMainWindow(): void { writeConfigFile('target-company-list.json', payload.expectCompanies.split(',')) ]) }) + + // const currentExecutablePath = app.getPath('exe') + // console.log(currentExecutablePath) + + let subProcessOfPuppeteer: ChildProcess + ipcMain.handle('run-geek-auto-start-chat-with-boss', async () => { + console.log(process) + subProcessOfPuppeteer = childProcess.spawn(process.argv[0], process.argv.slice(1), { + env: { + ...process.env, + MAIN_BOSSGEEKGO_RUN_MODE: 'geekAutoStartWithBoss' + } + }) + console.log(subProcessOfPuppeteer) + }) } diff --git a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue index 26c6634..743762c 100644 --- a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue +++ b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue @@ -77,6 +77,7 @@ 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)) } const handleSave = async () => { await formRef.value!.validate()