nathanbuchar / electron-settings

📝 A simple persistent user settings framework for Electron.

Home Page:https://electron-settings.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot read property 'app' of undefined

theArina opened this issue · comments

commented

Electron version: 10.0.0
Electron-settings version: 4.0.2
Platform: Windows 10

This function of the source depends on the "remote" module which is deprecated. In the new versions of the Electron it will be removed afaik.

 * Returns the Electron app. The app may need be accessed
 * via `Remote` depending on whether this code is running
 * in the main or renderer process.
 *
 * @returns The Electron app.
 * @internal
 */
function getElectronApp() {
    var _a;
    var e = getElectron();
    var app = (_a = e.app) !== null && _a !== void 0 ? _a : e.remote.app;
    return app;
}

I have the same issue on electron 10.x
Using 9.x works for now as a workaround

commented

@mathieupothier, have you tried to set the enableRemoteModule to true in 10x? as a workaround. cause i tried this just now, but it doesn't seems to work, that's weird.

I tested it in the past and it did not work back then. Got to try it again since you asked and I spotted an error on my end.

The enableRemoteModule: true needs to be in webPreferences: {}

Was:
new BrowserWindow({ enableRemoteModule: true });

Needed to be:
new BrowserWindow({ webPreferences: { enableRemoteModule: true }});

Now it works perfectly. So unless it's the same for you, it seems to be working with the flag properly set.

commented

@mathieupothier, yes, thank you for the tip. It works for me too with the flag inside webPreferences.
Might make a fork later to avoid using remote at all though.

I tested it in the past and it did not work back then. Got to try it again since you asked and I spotted an error on my end.

The enableRemoteModule: true needs to be in webPreferences: {}

Was:
new BrowserWindow({ enableRemoteModule: true });

Needed to be:
new BrowserWindow({ webPreferences: { enableRemoteModule: true }});

Now it works perfectly. So unless it's the same for you, it seems to be working with the flag properly set.

thanks. It works!

Hey thanks for the solution! I'll add this to the README.

commented

@nathanbuchar, no no no no, this is not a solution, this is a crutch.
well, i made a fork to avoid using the 'remote' module. it's kinda raw, but i still could make a pull request, would you like me to ?

Sorry, I misunderstood when glancing through this issue. Yes that would be very helpful, thank you!

Hi @nathanbuchar,
is there any update regarding the PR ? We're using electron-settings in a school project where we'll need to set enableRemoteModule to false.
Should we wait for a new release or try to use an other module ?

@ThibaultJousse thanks for bumping this. It's always been in the back of my mind, just haven't gotten around to it, for really no good reason :) I'll take care of this right now

After looking at the PR the other day, I learned that this fix is a bit more involved than I was originally expecting. Will in to dig in a bit more this weekend, sorry about that!

Hi there! Just wanted to follow up on this.

Hey! I know it's been a year but I just want to say that using the remote module is a huge security risk. You should instead use ipcMain, ipcRender, and contextBridge to send in the renderer process and receive in the main process.

Relevant links:

I appreciate you bumping this, however I have not used Electron in years. I'd highly recommend submitting a PR, as it's unlikely I will address this anytime soon

I appreciate you bumping this, however I have not used Electron in years. I'd highly recommend submitting a PR, as it's unlikely I will address this anytime soon

Sure! I'll submit a PR later to address this in the README.