// | ------------------------------------------------------------ // | @版本: version 0.1 // | @创建人: 【Nie-nie】 // | @E-mail: x71291@outlook.com // | @所在项目: js-ii-pad-linux // | @文件描述: task_01_createIpcChannel.js - // | @创建时间: 2024-11-12 10:08 // | @更新时间: 2024-11-12 10:08 // | @修改记录: // | -*-*-*- (时间--修改人--修改说明) -*-*-*- // | = // | ------------------------------------------------------------ import {ipcMain} from "electron"; import {handleIpcChannel_Started} from "./methods/handleIpcChannel.js"; import router from "./router/index.js"; export function createIpcChannel(win) { ipcMain.on(RenderChanleName, async (event, msg) => { console.log('渲染器消息', msg) switch (msg.type) { case 'Started': return handleIpcChannel_Started(msg) break; default: console.log('IPC UNKNOW', msg) } return; }) ipcMain.handle(RenderChanleName, async (event, msg) => { if (msg.path) { try { // 正常逻辑 const data = await router(msg) return { code: 200, message: 'success', data } } catch (e) { // 后台内部错误 console.log(e) return { code: 500, message: `ipc invoke bad request: ${msg.path}`, data: e } } } else { // 路径错误 return { code: 404, message: `ipc invoke not found path: ${msg.path}`, data: {} } } }) }