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) }