nathanbuchar / electron-settings

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

Doesn't work with Electron 14 #157

Closed ChugunovRoman closed 1 year ago

ChugunovRoman commented 3 years ago

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 commented 3 years ago

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

sarathkurup commented 3 years ago

same issue!!

sarathkurup commented 3 years ago

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

$ npm install electron-store

linonetwo commented 3 years ago

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.

caowenjin2 commented 3 years ago
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(),
 })
ramaralo commented 3 years ago

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.

jediwade commented 2 years ago

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