diff --git a/packages/dingtalk-plugin/index.mjs b/packages/dingtalk-plugin/index.mjs index 259eb1d..486a456 100644 --- a/packages/dingtalk-plugin/index.mjs +++ b/packages/dingtalk-plugin/index.mjs @@ -11,7 +11,7 @@ export default class DingtalkPlugin { setSendQueueTimer () { const _this = this const interval = 2 * 60 * 1000 - sendQueueTimer = setTimeout(function sendMergedMessage () { + function sendMergedMessage () { if (collectedMessageList.length === 0) { } else if (collectedMessageList.length === 1) { collectedMessageList[0].dingtalkRequestBody.text.content += `\n${dayjs(collectedMessageList[0].insertedTime).format('MM-DD HH:mm:ss')}\n\n【bossgeekgo】` @@ -29,7 +29,15 @@ export default class DingtalkPlugin { } collectedMessageList.length = 0 sendQueueTimer = setTimeout(sendMergedMessage, interval) - }, interval) + } + sendQueueTimer = setTimeout(sendMergedMessage, interval) + // FIXME: exit immediate without wait + process.on('SIGINT', () => { + sendMergedMessage() + setTimeout(() => { + process.exit(0) + }, 5000) + }) } destroySendQueueTimer () { clearTimeout(sendQueueTimer) diff --git a/packages/ui/src/main/window/mainWindow.ts b/packages/ui/src/main/window/mainWindow.ts index 783f1b3..f5aa855 100644 --- a/packages/ui/src/main/window/mainWindow.ts +++ b/packages/ui/src/main/window/mainWindow.ts @@ -80,8 +80,11 @@ export function createMainWindow(): void { // const currentExecutablePath = app.getPath('exe') // console.log(currentExecutablePath) - let subProcessOfPuppeteer: ChildProcess + let subProcessOfPuppeteer: ChildProcess | null = null ipcMain.handle('run-geek-auto-start-chat-with-boss', async () => { + if (subProcessOfPuppeteer) { + return + } console.log(process) subProcessOfPuppeteer = childProcess.spawn(process.argv[0], process.argv.slice(1), { env: { @@ -89,6 +92,16 @@ export function createMainWindow(): void { MAIN_BOSSGEEKGO_RUN_MODE: 'geekAutoStartWithBoss' } }) + ipcMain.emit('geek-auto-start-chat-with-boss-started') + subProcessOfPuppeteer.once('exit', () => { + mainWindow.webContents.send('geek-auto-start-chat-with-boss-stopped') + + subProcessOfPuppeteer = null + }) console.log(subProcessOfPuppeteer) }) + ipcMain.handle('stop-geek-auto-start-chat-with-boss', async () => { + mainWindow.webContents.send('geek-auto-start-chat-with-boss-stopping') + subProcessOfPuppeteer?.kill('SIGINT') + }) } diff --git a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue index 743762c..5c7b8c1 100644 --- a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue +++ b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue @@ -34,6 +34,7 @@ import { ref } from 'vue' import JSON5 from 'json5' import { ElForm, ElMessage } from 'element-plus' +import router from '../../router/index'; const formContent = ref({ bossZhipinCookies: '', @@ -78,6 +79,7 @@ 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)) + router.replace('/geekAutoStartChatWithBoss/runningStatus') } const handleSave = async () => { await formRef.value!.validate() diff --git a/packages/ui/src/renderer/src/page/GeekAutoStartChatWithBoss/RunningStatus.vue b/packages/ui/src/renderer/src/page/GeekAutoStartChatWithBoss/RunningStatus.vue new file mode 100644 index 0000000..e8b9b96 --- /dev/null +++ b/packages/ui/src/renderer/src/page/GeekAutoStartChatWithBoss/RunningStatus.vue @@ -0,0 +1,32 @@ + + + + + diff --git a/packages/ui/src/renderer/src/page/GeekAutoStartChatWithBoss/index.vue b/packages/ui/src/renderer/src/page/GeekAutoStartChatWithBoss/index.vue new file mode 100644 index 0000000..f21a49f --- /dev/null +++ b/packages/ui/src/renderer/src/page/GeekAutoStartChatWithBoss/index.vue @@ -0,0 +1 @@ + diff --git a/packages/ui/src/renderer/src/router/index.ts b/packages/ui/src/renderer/src/router/index.ts index 3a6f07e..cc8d52b 100644 --- a/packages/ui/src/renderer/src/router/index.ts +++ b/packages/ui/src/renderer/src/router/index.ts @@ -21,6 +21,19 @@ const routes: Array = [ } } ] + }, + { + path: '/geekAutoStartChatWithBoss', + component: () => import('@renderer/page/GeekAutoStartChatWithBoss/index.vue'), + children: [ + { + path: 'runningStatus', + component: () => import('@renderer/page/GeekAutoStartChatWithBoss/RunningStatus.vue'), + meta: { + title: 'geek auto start chat with boss is running!' + } + } + ] } ]