st-modified-electron-app-settings

1.0.3 • Public • Published

electron-app-settings

An easy-to-use, efficient, and multi-process safe settings framework for Electron that presumes a single application configuration file.

Written to allow settings to be shared between the main process and renderer processes through ipcMain and ipcRenderer communication. The main process acts as the master to all renderer processes, loading the initial configuration file, managing synchronization, and the saving of the configuration on application quit.

Compatible with electron-config generated configuration files.

  • Advantages
    • Simple syntax allowing for escaped dot notation
      • e.g., "my\.property" => {"my\.property": ...}
    • Automatic merging of default values
    • IPC-based with no-config settings synchronization
    • Simple to use -- require wherever needed and begin usage!
  • Disadvantages
    • No key=>value monitoring (yet)
    • Only save-on-quit (to be further expanded)
    • Single settings file (could be changed, but might be beyond the module's scope)

Installation

$ npm install electron-app-settings --save

Usage

electron-app-settings can simply be required wherever it is needed, regardless of if it has been loaded in the main process or not, as the module will automatically handle setting itself up in the main process.

The configuration file is presumed to be located at "userData/Settings" and will be saved on application quit.

// MAIN PROCESS
const settings = require('electron-app-settings');
 
settings.set('cat', {
  name: 'Cat',
  limbs: 4,
  fuzzy: true
});
 
settings.get('cat.name');
// => "Cat"
 
settings.has('cat.bark');
// => false
 
/* Object-only merge-style defaults */
settings.set({
  { dog: {
    name: "Dog",
    tail: true
  }
}, true);
 
settings.get('cat');
// => {name: "Cat", limbs: 4, fuzzy: true, tail: true}
settings.get('dog');
// => {name: "Dog", tail: true}
 
// RENDERER PROCESS
const settings = require('electron-app-settings');
 
// ... on app-ready
  settings.get('cat');
  // => {name: "Cat", limbs: 4, fuzzy: true, tail: true}

Package Sidebar

Install

npm i st-modified-electron-app-settings

Weekly Downloads

1

Version

1.0.3

License

GPL-3.0

Unpacked Size

49.9 kB

Total Files

7

Last publish

Collaborators

  • karambir-sentieo