nathanbuchar / electron-settings

📝 A simple persistent user settings framework for Electron.
https://electron-settings.js.org
MIT License
814 stars 60 forks source link

Cannot read property 'app' of undefined #133

Closed theArina closed 3 years ago

theArina commented 4 years ago

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;
}
mathieupothier commented 4 years ago

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

theArina commented 4 years ago

@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.

mathieupothier commented 4 years ago

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.

theArina commented 4 years ago

@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.

ckissi commented 4 years ago

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!

nathanbuchar commented 3 years ago

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

theArina commented 3 years ago

@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 ?

nathanbuchar commented 3 years ago

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

ThibaultJousse commented 3 years ago

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 ?

nathanbuchar commented 3 years ago

@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

nathanbuchar commented 3 years ago

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!

dmitrif commented 2 years ago

Hi there! Just wanted to follow up on this.

TechStudent10 commented 1 year ago

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:

nathanbuchar commented 1 year ago

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

TechStudent10 commented 1 year ago

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.