Access Browser window of electron in a component;


I’m using electron with ionic 2, and I want to add a setting change the vibrancy, but change this I had to access the variable win of the electron.js, how can I do that?


Theres an important distinction to be made when working with ionic and electron.
The ionic instance runs in a render process (webview-ish) and does not have access to the system(security reasons) and the electron application that runs in the main process and has access to system API’s like reading files, system settings etc

To communicate between your electron and ionic app you need to make ipc calls

Example of firebase admin SDK that needs to run in a NodeJS context and can not run within a render process context

Ionic bits

// @ts-ignore
const {ipcRenderer} = window.require('electron');

/*STEP 3 Handle the data coming from the event*/
ipcRenderer.on('GET_USERS_RESP', this.myHandlerFunction)

 /* STEP 1 Ask for info from Electron*/

Electron bits in my main.js

const {ipcMain} = require('electron')

/*STEP 2 electron uses whatever native functionality you need and triggers an event*/
ipcMain.on('GET_USERS_REQ', (event, arg) => {
        .then(users => event.sender.send('GET_USERS_RESP', users))
        .catch(err => console.log("GET USER LIST ERR:", err));

I hope this helps.
If anyone nows a better way or a nice abstraction let me know