J0nny
J0nny

Reputation: 11

remote function returns undefined or null in electron renderer process

I'm currently very interested in the comprehensive opportunites granted by electron.js and its modules. Unfortunately, I keep getting the same error in my renderer process (named 'connector.js') when trying to start my application.

Here is the error:

App threw an error during load
TypeError: Cannot match against 'undefined' or 'null'.
    at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\extFunctions\connector\connector.js:2:44)
    at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\extFunctions\connector\connector.js:22:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\main.js:9:1)

And here is my connector.js:

const $ = require('jquery');
const {BrowserWindow} = require('electron').remote;

let Remotewin = remote.getFocusedWindow();

$("#minimize").click(function(){
  Remotewin.minimize();
});

$("#maximize").click(function(){
  if(!Remotewin.isMaximized()){
    Remotewin.maximize();
  }else{
    Remotewin.unmaximize();
  }
});

$("#close").click(function(){
  Remotewin.close();
});

As you can see clearly, I wanted to create my own menubar at the top frame of the window, but the functionality is getting seemingly demolished by this error. I already searched half of the internet and stackoverflow, but the every answer I found refered to a webpack and/or electron bug they couldn't directly influence.

That's why I want to clearly point out, that I am NOT using webpack in this project. Only external module I added is jquery, as you can see in the code.

So my question; Have you experiended this error in this context and do you maybe even know a solution? Or can you refer to someone with similiar problems?

Thank you in advance, J0nny

Upvotes: 0

Views: 1631

Answers (1)

user8022331
user8022331

Reputation:

Since getFocusedWindow() is a a static method of BrowserWindow,

let Remotewin = remote.getFocusedWindow();

should be:

let Remotewin = BrowserWindow.getFocusedWindow();

Upvotes: 1

Related Questions