Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple settings files? #92

Open
stavlocker opened this issue Jul 27, 2017 · 5 comments
Open

Multiple settings files? #92

stavlocker opened this issue Jul 27, 2017 · 5 comments

Comments

@stavlocker
Copy link

Hi. Great project!
Could it be possible for us to use multiple settings files? It'd make this project ideal for me.
Thanks in advance!

@nathanbuchar
Copy link
Owner

nathanbuchar commented Jul 27, 2017

Hi @stavlocker,

I'm afraid this capability does not currently exist and there are no current plans to implement it in the near future. So that I can get a sense of how a feature like this would be used, may I ask how multiple settings files would be ideal for your project and how having one does not work for you?

Thanks :)

@stavlocker
Copy link
Author

@nathanbuchar Well, an example might be saving data, and not only settings - I could have my config.json file to manage the configuration, and my cupcakes.json to save all the cupcakes a user made on my app (or any other less stupid example). It would be excellent for saving data that I may not want in my config files (sort of a mini-database if you want to think of it that way).

@nathanbuchar
Copy link
Owner

I can certainly understand wanting to split data into their own files, but with electron-settings you could just scope settings within their own key or namespace, like so:

settings.set('config', {
  isLoggedIn: true,
  username: 'nathanbuchar'
});

settings.set('cupcakes', [
  'Red Velvet',
  'Vanilla',
  'Chocolate'
]);

settings.get('config.isLoggedIn'); // true
settings.get('cupcakes')[0]; // 'Red Velvet'

If you're still keen on having different files for each config, check out electron-json-storage. There, each key is its own JSON file—there's no concept of "key paths". It's kind of like a re-implementation of LocalStorage, where a JSON file is created for each key.

@EmadAdly
Copy link

@nathanbuchar Maybe an unexpected error occurred while write, It may cause damage for file, also there are many possible causes for data damage. so which will cause all data to be lost.
do not put your eggs in one basket
So I think their separation will be logical in this case.

@wilburforce83
Copy link

I know this is super old, but if anyone else needs this, I have gone for creating a backup after and before critical changes are made in the application. I then have a simple function which looks for setting on startup, if they are not there, then copy this file in place of setting and voila, setting are back :) :

function postTradeBackup() {

     var fileName;

     var location = settings.file() //.slice(0, -8) for folder location
     var content;



     fs.readFile(location, 'utf-8', (err, data) => {
         if (err) {
             console.log("An error ocurred reading the file :" + err.message);
             return;
         }

        
         // console.log("The file content is : " + data);
         fileName = location + '1'; // could be .bkp or whatever
         content = data;
         //  console.log(fileName);
         // fileName is a string that contains the path and filename created in the save file dialog.  
         fs.writeFile(fileName, content, (err) => {
             if (err) {
                 console.log("An error ocurred creating the file " + err.message)
                 return;
             }

             //     console.log("Settings has been succesfully backed up");
         });
     });
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants