electron-settings icon indicating copy to clipboard operation
electron-settings copied to clipboard

Doesn't work with Electron 14

Open ChugunovRoman opened this issue 4 years ago • 7 comments

Current version (4.0.2) of Electron-settings doesn't work with new version Electron. I use Electron v14.1.1 I got a error in render process:

screenshot_2021-10-11T21:07:18

ChugunovRoman avatar Oct 11 '21 18:10 ChugunovRoman

https://github.com/electron/remote#migrating-from-remote

ChugunovRoman avatar Oct 11 '21 18:10 ChugunovRoman

same issue!!

sarathkurup avatar Oct 21 '21 18:10 sarathkurup

alternative https://www.npmjs.com/package/electron-store

$ npm install electron-store

sarathkurup avatar Oct 21 '21 18:10 sarathkurup

It works!

you can use https://github.com/linonetwo/electron-ipc-cat to proxy the request to your preference services, just like how I'm doing in https://github.com/tiddly-gittly/TiddlyGit-Desktop

Hope my code example and npm package helps.

linonetwo avatar Oct 26 '21 11:10 linonetwo

Snipaste_2021-10-27_14-53-28

You can fix it temporarily by provide a custom Electron instance;

const getElectron = () => {
    const electron = window.require('electron');
    // @ts-ignore
    electron.remote = electron.remote || window.require('@electron/remote');
    return electron;
}
const settings = window.require('electron-settings');
settings.configure({
     electron: getElectron(),
 })

caowenjin2 avatar Oct 27 '21 06:10 caowenjin2

For those still in v.3.# we can workaround this by:

const remote = require("@electron/remote");

settings.setPath(path.join(remote.app.getPath("userData"), "Settings"));

This will still point to the default file but because it's using a custom path, electron-settings won't try to use remote from the electron dependency.

ramaralo avatar Nov 03 '21 10:11 ramaralo

@ChugunovRoman I am assuming you are trying to use electron-settings in the Renderer (you should provide more information in your bug reports). If you want to use the newer versions of Electron and have access to higher level APIs like remote, you need to make use of the context isolation feature to create a limited API that can be called from the Renderer. You shouldn't try to get around the security changes Electron has implemented. Yes the context isolation is a pain, but it is in the app user's best interest of your app.

jediwade avatar Nov 27 '21 02:11 jediwade