Reputation: 36217
I'm currently looking int a project with Electron. I am looking at making myself a little utility app, where, when I do this normally, in such as C# or C++ I create an ini file which is in the same location of the executable so I can load it and change various settings without the need to rebuild the app, or have any complicated settings screen from within the app itself.
I want to do something similar with Electron but I can't see where this is possible. I can find areas where you can read local files that are external to the electron app that are on disk but not files that are bundled with the app.
I.e. I can open an ini file when the electron app loads (the ini file will always be present, there won't be a chance where it won't be, and when it comes to being bundled and installed for deployment, the ini file will be with the executable so I can modify the ini file manually and then reload the electron app which would read the ini file.
Hopefully this makes sense
Upvotes: 1
Views: 2654
Reputation: 1467
You can use the electron and fs modules to access configuration files stored on your computer outside of the electron app. Instead of .ini files, I would suggest using .json files, they are easily parsed and managed within javascript. Here is an example to try from your rendering thread (just remove the remote to use from main thread):
import electron from 'electron';
import fs from 'fs';
const data = fs.readFileSync(pathToSettingsJSON);
const json = data.toString('utf8');
console.log(`settings JSON: ${json}`);
settings = JSON.parse(json);
You would then have a javascript object called settings that would contain properties from your JSON text file.
Upvotes: 0