arcovoltaico arcovoltaico - 7 months ago 39
AngularJS Question

Accesing one of the opened windows from a controller

I have created 2 windows in main.js

app.on('ready', () => {
mainWindow = new BrowserWindow({
width: mainWindowState.width,
height: mainWindowState.height,
minWidth: 800,
minHeight: 600,
x: mainWindowState.x,
y: mainWindowState.y,


playerWindow = new BrowserWindow({
width: playerWindowState.width,
height: playerWindowState.height,
minWidth: 800,
minHeight: 600,
x: playerWindowState.x,
y: playerWindowState.y,

Now I'd tried to access the playerWindow from a controller.
I used remote, global, different approached but I did not able to access the global window array defined on main.js from the controller, so I still don't know how to access the playerWindow to be able to do this:

playerWindow.location.href = '#/player';

Any idea? Thanks!

Answer Source

This task can be achieved using IPC.

On the controller just add:

const {ipcRenderer} = require('electron');
$scope.openPlayer = function () {
    $scope.playerOpen = true;
    ipcRenderer.send('open-player-window', 'an-argument');

$scope.closePlayer = function () {
    $scope.playerOpen = false;
    ipcRenderer.send('close-player-window', 'an-argument');


And on the main.js

const {app, BrowserWindow, electron, ipcMain} = require('electron');

app.on('ready', () => {

mainWindow = new BrowserWindow(etc... //

ipcMain.on('close-player-window', (event, arg) => {

ipcMain.on('open-player-window', (event, arg) => {
    playerWindow = new BrowserWindow({etc...});

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download