From 4cd3a4456522514e04c11095ee3aa94d669250e4 Mon Sep 17 00:00:00 2001 From: Osandi-Hirimuthugoda Date: Thu, 8 Feb 2024 22:08:15 +0530 Subject: [PATCH] Add preload.js to solve window.require error --- imagelab_react/public/electron.js | 1 + imagelab_react/public/preload.js | 5 +++++ imagelab_react/src/browse-blocks-functions.js | 3 +-- imagelab_react/src/utils/main.js | 3 +-- 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 imagelab_react/public/preload.js diff --git a/imagelab_react/public/electron.js b/imagelab_react/public/electron.js index 1031e67..0bfee92 100644 --- a/imagelab_react/public/electron.js +++ b/imagelab_react/public/electron.js @@ -13,6 +13,7 @@ function createWindow() { webPreferences: { nodeIntegration: true, contextIsolation: false, + preload: path.join(__dirname, './preload.js'), }, }); diff --git a/imagelab_react/public/preload.js b/imagelab_react/public/preload.js new file mode 100644 index 0000000..422ebf4 --- /dev/null +++ b/imagelab_react/public/preload.js @@ -0,0 +1,5 @@ +const { ipcRenderer } = require("electron"); + +process.once("loaded", () => { + window.ipcRenderer = ipcRenderer; +}); diff --git a/imagelab_react/src/browse-blocks-functions.js b/imagelab_react/src/browse-blocks-functions.js index a66a855..6d096ca 100644 --- a/imagelab_react/src/browse-blocks-functions.js +++ b/imagelab_react/src/browse-blocks-functions.js @@ -1,6 +1,5 @@ import Blockly from "blockly"; -const electron = window.require('electron'); -const ipcRenderer = electron.ipcRenderer; +const ipcRenderer = window.ipcRenderer; /*This function is responible for opening file selector window to choose the picture you will do operqations on it works with (read image) block */ diff --git a/imagelab_react/src/utils/main.js b/imagelab_react/src/utils/main.js index 20aa6da..5f0e243 100644 --- a/imagelab_react/src/utils/main.js +++ b/imagelab_react/src/utils/main.js @@ -1,6 +1,5 @@ import Blockly from "blockly"; -const electron = window.require('electron'); -const ipcRenderer = electron.ipcRenderer; +const ipcRenderer = window.ipcRenderer; function processBlock(block, pipeline) { const blockParams = block.inputList.reduce((params, input) => {