preference-manager

Save your Electron app setting to a local file

Usage no npm install needed!

<script type="module">
  import preferenceManager from 'https://cdn.skypack.dev/preference-manager';
</script>

README

Preference Manager

Save your Electron app setting to a local file

Quick save and load app window settings with a single line of code. Auto-remove empty settings and many more features. Module works both in main and render processes.

Installation

npm install preference-manager

Quick save window params {x, y, width, height}

const pm = require('preference-manager');

app.on('ready', function(){
   win.on('close', function(){
      pm.quicksave();
   });
});

Load and apply settings to the window

app.on('ready', function(){
   pm.quickload();
});

Save custom settings

pm.save({a: 1, b: 2, c: {d: 3}});

Save settings and remove empty ones

pm.save({a: null, b: 2, c: {d: null}, d: new Date}, true);
// => {b: 2, d: "2011-02-15T11:22:40.263Z"}

Load

pm.load();
// => {a: 1, b: 2, c: {d: 3}}

Delete all

pm.flush();
// => {}

List all settings (with beautify = true)

pm.list(true);
/*
   { 
      a: 1, 
      b: 2, 
      c: {
         d: 3
      }
   }
*/

Get settings file

pm.file;
//=> C:\Users\me\AppData\Roaming\app\.settings

Changelog

2018-03-15:

  • v2.0.2 Now quickload method will never position your app outside the screen bounds (if, for example, you disabled the second monitor, where was your app on)

2018-03-04:

  • v2.0.1 Fixed bug, when app trying to save setting but app's userData folder does not exist yet

2018-02-13:

  • v2.0.0 Rewritten from ground up. Added few more stuff to manage your settings