Where to store user settings in Electron (Atom Shell) Application?

前端 未结 6 913
你的背包
你的背包 2020-12-07 14:45

I can\'t seem to locate a built in mechanism to store user settings. I was hoping that electron provided a standard method for storing user settings across all desktop platf

6条回答
  •  無奈伤痛
    2020-12-07 15:06

    I've faced this particular problem with my Electron app and this post inspired me to write an NPM module called electron-json-storage.

    This module allows to easily write/read JSON to/from app.getPath('userData'):

    const storage = require('electron-json-storage');
    
    // Write
    storage.set('foobar', { foo: 'bar' }).then(function() {
    
        // Read
        storage.get('foobar').then(function(object) {
            console.log(object.foo);
            // will print "bar"
        });
    
    });
    

提交回复
热议问题