settings-store

Source: settings-store.js:10

Pure settings-store logic — plain Node, no Electron. src/settings.js owns the Electron-resolved file location (app.getPath('userData')) and the in-memory cache; this module owns the default schema, the deep-merge rules, and the never-throw read / atomic write, so the durability guarantees run anywhere Node runs. Callers pass the settings.json path explicitly.


Instance Methods

mergeDefaults(defaults: *, target: *): *

Recursively fill any keys missing from target with values from defaults. This is what makes the store forward-compatible: a settings.json written before a new field existed still yields a complete object, with new fields at their defaults. Plain objects are merged key-by-key; arrays and primitives are taken wholesale from target.

Parameters

  • defaults (*) — Default value or schema branch.
  • target (*) — Stored value or patch branch; undefined falls back to the default.

Returns

  • * — The merged result.

isPlainObject(v: *): boolean

Whether a value is a plain object (not null, not an array).

Parameters

  • v (*) — Candidate value.

Returns

  • boolean — True for non-null, non-array objects.

read(file: string): Object

Read settings from disk and merge against the defaults. A missing file (fresh install) or a corrupt/unparseable file both fall back to a deep copy of the defaults — read() never throws, so a bad file can't brick app launch.

Parameters

  • file (string) — Absolute path of settings.json.

Returns

  • Object — Complete settings object.

persist(file: string, data: Object): void

Atomic write: serialize to a temp file in the same directory, then rename over the real file. rename() is atomic on a single filesystem, so a crash mid-write can't leave a half-written settings.json — readers see either the old file or the complete new one. Creates the parent directory first (userData may not exist on first run).

Parameters

  • file (string) — Absolute path of settings.json.
  • data (Object) — Settings object to persist.

Returns

  • void

Other

DEFAULTS: Object

Default shape. Every key the app reads must exist here so a fresh install — or a settings file written by an older version — always resolves to a complete object after the deep-merge in read(). Bump version when the shape changes incompatibly.

Field notes: files.defaultSaveFolder — null means "no explicit choice — fall back to ~/Downloads"; kept null rather than baking in the Downloads path so the fallback follows the user across machines. files.nameAffix — text added to every exported layback name, e.g. "NB_" → NB_SummerNights.mp4; position is 'before' (prefix) or 'after' (suffix). metadata — optional tags written into export metadata (ticket F2); empty strings = not written. artworkPath is an absolute path to a JPEG/PNG used as cover artwork, or null; stored as a path for now — a future pass may copy the image into userData so it survives the source moving. integrations — non-secret connection state only (see src/settings.js header); the actual tokens live in the keychain via safeStorage, keyed by service name. app.checkUpdatesOnLaunch — background update checks (launch + every 4h). ON by default: staying current is the behavior every install has had, and a stranded old version is a support and security liability. Turning it off silences the BACKGROUND checks only — the "Check for Updates…" menu item always works. app.promptedUpdateVersion — last update version the restart dialog was shown for. update-downloaded re-fires every launch until the update installs; this is what keeps the dialog to one appearance per version (see updater.js shouldPrompt).