Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ipcrenderer main.js

const {
  app,
  BrowserWindow,
  ipcMain
} = require("electron");
const path = require("path");
const fs = require("fs");

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;

async function createWindow() {

  // Create the browser window.
  win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: false, // is default value after Electron v5
      contextIsolation: true, // protect against prototype pollution
      enableRemoteModule: false, // turn off remote
      preload: path.join(__dirname, "preload.js") // use a preload script
    }
  });

  // Load app
  win.loadFile(path.join(__dirname, "dist/index.html"));

  // rest of code..
}

app.on("ready", createWindow);

ipcMain.on("toMain", (event, args) => {
  fs.readFile("path/to/file", (error, data) => {
    // Do something with file contents

    // Send result back to renderer process
    win.webContents.send("fromMain", responseObj);
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: jest wait for timeout 
Javascript :: javascript calculate average of array 
Javascript :: capitalize all letters jquery 
Javascript :: jquery selector id ends with 
Javascript :: javascript The replace() method 
Javascript :: react styled functional component 
Javascript :: javascript define multidimensional array 
Javascript :: how to initialize empty javascript object 
Javascript :: location.reload() js 
Javascript :: mongoose show all indexes 
Javascript :: event.currenttarget 
Javascript :: p5js click on button 
Javascript :: add 1 year to given date in javascript 
Javascript :: override important css 
Javascript :: slide hide animaition in react 
Javascript :: react native get os 
Javascript :: disable input box javascript 
Javascript :: js reverse linked list 
Javascript :: css vw not working on mobile 
Javascript :: async function javascript 
Javascript :: javascript remove object from array 
Javascript :: how to generate a new page component in angular 
Javascript :: jquery get custom attribute 
Javascript :: jQuery Effects - Fading 
Javascript :: useeffect cleanup in reactjs 
Javascript :: append to map javascript 
Javascript :: react eslint prettier 
Javascript :: string length in javascript 
Javascript :: palindrome javascript 
Javascript :: capitalize first letter of each word 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =