47 lines
1.4 KiB
Plaintext
47 lines
1.4 KiB
Plaintext
# Simple Electron App Settings Management
|
|
Written as a replacement for the rather nice but somewhat insufficient (for my needs) [electron-settings](https://github.com/nathanbuchar/electron-settings), I hereby present [electron-app-settings](https://github.com/kettek/electron-app-settings), a **multi-process safe app settings library** for [Electron](https://electronjs.org/).
|
|
|
|
This module is being used in the soon-to-be released Open Markup Editor (development visibile @ its [GitHub page](https://github.com/kettek/open-markup-editor)) and has proven itself to be far nicer to use than other non-IPC based settings libraries that were tried.
|
|
|
|
Usability is a cinch:
|
|
|
|
```
|
|
// In your main process
|
|
const settings = require('electron-app-settings');
|
|
settings.set('my_var', 'my_value');
|
|
settings.set({my_obj: 10});
|
|
|
|
settings.get('my_var');
|
|
// => 'my_value'
|
|
settings.get();
|
|
// => {'my_var': 'my_value', 'my_obj': 10}
|
|
|
|
// In your renderer process
|
|
const settings = require('electron-app-settings');
|
|
settings.get('my_obj');
|
|
// => 10
|
|
settings.set('my_obj', 20);
|
|
```
|
|
|
|
Setting default settings:
|
|
|
|
```
|
|
// In your main process
|
|
const settings = require('electron-app-settings');
|
|
|
|
// Merge these settings under any existing settings
|
|
settings.set({
|
|
window: {
|
|
width: 800,
|
|
height: 600,
|
|
left: -1,
|
|
top: -1
|
|
},
|
|
update_delay: 250
|
|
}, true);
|
|
```
|
|
|
|
All settings are saved on application quit.
|
|
|
|
See the [github page](https://github.com/kettek/electron-app-settings) for more information.
|