Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

electron how to setup preload.js

// Preload.js setup example
const { contextBridge, ipcRenderer } = require("electron")

// Expose valid channels for ipc.render methods inside array
const ipc = {
    render: {
        send: [],
        receive: [],
        sendRecieve: [],
    }
};

contextBridge.exposeInMainWorld(
    "ipcRender", {
        // From render to main.
        send: (channel, args) => {
            let validChannels = ipc.render.send;
            if (validChannels.includes(channel)) {
                ipcRenderer.send(channel, args);
            }
        },
        // From main to render.
        receive: (channel, listener) => {
            let validChannels = ipc.render.receive;
            if (validChannels.includes(channel)) {
                ipcRenderer.on(channel, (event, args) => listener(args));
            }
        },
        // From render to main and back again.
        invoke: (channel, args) => {
            let validChannels = ipc.render.sendReceive;
            if (validChannels.includes(channel)) {
                return ipcRenderer.invoke(channel, args);
            }
        }
    }
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript keyup event enter key 
Javascript :: select in react js 
Javascript :: nextjs global scss variables 
Javascript :: define an unsigned long int js 
Javascript :: javascript random number up to including 2 
Javascript :: checkbox jquery checked 
Javascript :: lookup in mongodb array 
Javascript :: express router file 
Javascript :: javascript competitive programming 
Javascript :: loading 
Javascript :: dm command discord.js 
Javascript :: CastError: Cast to ObjectId failed for value "undefined" at path "_id" for model 
Javascript :: countdown in js 
Javascript :: error metro bundler process exited with code 1 react native 
Javascript :: phaser change background color 
Javascript :: mongodb push to index 
Javascript :: javascript get last object in foreach loop 
Javascript :: nodejs routes 
Javascript :: nodemon watch extensions 
Javascript :: copy text on click 
Javascript :: jquery parent 
Javascript :: indexof method javascript 
Javascript :: png to base64 javascript 
Javascript :: create new angular project with specific version 
Javascript :: send mail, nodemailer, nodemailer, mailer, nodemailer npm 
Javascript :: how to find date in a string js 
Javascript :: regex usage 
Javascript :: how to play audio in javascript 
Javascript :: how to send axios delete to the backend reactjs 
Javascript :: reactjs join two array 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =