How to pass parameters from main process to render processes in Electron

A few methods: loadURL Query String The query string method others have posted seems to work fine. It might even be the easiest. additionalArguments Electron’s documentation says additionalArguments is: Useful for passing small bits of data down to renderer process preload scripts. Main const win = new BrowserWindow({ width: 800, height: 600, backgroundColor: ‘#000000’ webPreferences: … Read more

How to catch the event of clicking the app window’s close button in Electron app

You can catch it by using the close event of the browser-window api. You can try the following to verify this… var app = require(‘app’); var force_quit = false; app.on(‘ready’, function () { mainWindow = new BrowserWindow({ width: 800, height: 600 }); mainWindow.on(‘close’, function() { // <—- Catch close event // The dialog box below … Read more

Electron – How to add external files?

Managed to solve it by using extraResources. Should be declared under build in your package.json file. For example: Create a new folder named extraResources adjacent to pacakge.json Add the following code to your package.json file: “build”: { “extraResources”: [“./extraResources/**”] } Then, you can access the files inside this folder by using __dirname + ‘/../extraResources/’ from … Read more

What’s the proper way to handle forms in Electron?

We use a service (Angular) to process form data in a window. Then notify the remote, if needed. From your renderer you can send data to the ipc, then in your main.js you catch this event and the passed form data: // renderer.js let ipcRenderer = require(‘electron’).ipcRenderer; ipcRenderer.send(‘submitForm’, formData); // main.js ipcMain.on(‘submitForm’, function(event, data) { … Read more

How to make the dev tools not show up on screen by default in Electron?

Just comment or remove this line of code in main.js file (setting devTools to false) this.mainWindow.openDevTools(); (or) Add the following code to mainWindow = new BrowserWindow({ width: 1024, height: 768, webPreferences: { devTools: false } }); (or) change the package.json build to npm run build && build –win –x64 (or) again install npm

electron – node.js – ng : file path\ng.ps1 cannot be loaded because running scripts is disabled on this system

You have to set your execution policy to Unrestricted not RemoteSigned. According to Set-ExecutionPolicy: RemoteSigned. Requires that all scripts and configuration files downloaded from the Internet are signed by a trusted publisher. The default execution policy for Windows server computers. Since 99% of all PowerShell scripts are unsigned, 99% of the time you will not … Read more

Electron open file/directory in specific application

You can open a file or folder through shell commands from the electron module. The commands work on both main and renderer process. const {shell} = require(‘electron’) // deconstructing assignment shell.showItemInFolder(‘filepath’) // Show the given file in a file manager. If possible, select the file. shell.openPath(‘folderpath’) // Open the given file in the desktop’s default … Read more

tech