From fd9cb38d1d4ad369fb91d2d45450318b4c5a0687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=BF=97=E5=BC=BA?= Date: Thu, 1 Feb 2024 18:24:43 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E9=80=BB=E8=BE=91=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/demos/ipc.ts | 23 ++++++++++++++++++++++- src/store/task.ts | 2 +- src/views/cron/index.vue | 7 ++++--- src/views/cron/useTask.ts | 5 +++-- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/demos/ipc.ts b/src/demos/ipc.ts index 38a704b..130f715 100644 --- a/src/demos/ipc.ts +++ b/src/demos/ipc.ts @@ -1,8 +1,29 @@ +import { useMessage } from '../composables/useMessage' +import { Task } from '../store/task' + +const { sendMsgBatch } = useMessage() + window.ipcRenderer.on('main-process-message', (_event, ...args) => { console.log('[Receive Main-process message]:', ...args) }) window.ipcRenderer.on('main-process-cron-message', (_event, ...args) => { console.log('[Receive Main-process corn message]:', ...args) - // TODO: send message + + const task = args[0] as Task + + if (!Array.isArray(task.receiver_ids)) return + + // Send message to receiver + sendMsgBatch(task.receiver_ids, { + mode: task.type, + ...task.params + }) + + console.log( + '[Send Msg Batch]:', + task.receiver_ids.join('、'), + task.type, + task.params + ) }) diff --git a/src/store/task.ts b/src/store/task.ts index c36ea07..0088f18 100644 --- a/src/store/task.ts +++ b/src/store/task.ts @@ -13,7 +13,7 @@ export interface Task { mode: TaskMode type: MessageType name: string - receiver_ids: number[] + receiver_ids: string[] cron: string enabled: boolean params: any diff --git a/src/views/cron/index.vue b/src/views/cron/index.vue index d70e6ec..5baf8a0 100644 --- a/src/views/cron/index.vue +++ b/src/views/cron/index.vue @@ -19,9 +19,10 @@ diff --git a/src/views/cron/useTask.ts b/src/views/cron/useTask.ts index be5f789..1a9be09 100644 --- a/src/views/cron/useTask.ts +++ b/src/views/cron/useTask.ts @@ -68,11 +68,12 @@ export const useTask = () => { } const handleEditTask = (index: number, task: Task) => { + CronTask.stop(task) + if (task.enabled) { CronTask.start(task) - } else { - CronTask.stop(task) } + editTask(index, task) }