From db3fe91bf088eb032df66f9e1d5b431df9d958d4 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Tue, 21 Nov 2023 19:13:06 +0100 Subject: [PATCH] use sendToRender --- src/main/utils/sendToRender.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/utils/sendToRender.js diff --git a/src/main/utils/sendToRender.js b/src/main/utils/sendToRender.js new file mode 100644 index 0000000..8059d87 --- /dev/null +++ b/src/main/utils/sendToRender.js @@ -0,0 +1,23 @@ +import lodash from "lodash" + +export default (event, data) => { + function serializeIpc(data) { + if (!data) { + return undefined + } + + const copy = lodash.cloneDeep(data) + + if (!Array.isArray(copy)) { + Object.keys(copy).forEach((key) => { + if (typeof copy[key] === "function") { + delete copy[key] + } + }) + } + + return copy + } + + global.win.webContents.send(event, serializeIpc(data)) +} \ No newline at end of file