electron-settings
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -18,3 +18,3 @@ 'use strict'; | ||
/** | ||
* Local reference to the Electron app. | ||
* Called when the settings file is changed or renamed. | ||
* | ||
@@ -24,21 +24,5 @@ * @type {Object} | ||
*/ | ||
this._app = electron.app || electron.remote.app; | ||
this._handleSettingsChange = this._onSettingsChange.bind(this); | ||
/** | ||
* The path to the user data folder for the current app. | ||
* | ||
* @type {string} | ||
* @private | ||
*/ | ||
this._userDataPath = this._app.getPath('userData'); | ||
/** | ||
* The absolute path to the settings file. | ||
* | ||
* @type {string} | ||
* @private | ||
*/ | ||
this._settingsPath = path.join(this._userDataPath, 'Settings'); | ||
/** | ||
* The FSWatcher instance. This will watch if the settings file and | ||
@@ -52,10 +36,18 @@ * notify key path observers. | ||
this._fsWatcher = null; | ||
} | ||
/** | ||
* Called when the settings file is changed or renamed. | ||
* | ||
* @type {Object} | ||
* @private | ||
*/ | ||
this._handleSettingsChange = this._onSettingsChange.bind(this); | ||
/** | ||
* Gets the absolute path to the user settings file. This is done | ||
* dynamically instead of being cached during instantiation because | ||
* it is possible to change the user data path programatically. | ||
* | ||
* @returns {string} | ||
* @private | ||
*/ | ||
_getSettingsPath() { | ||
const app = electron.app || electron.remote.app; | ||
const userDataPath = app.getPath('userData'); | ||
const settingsFilePath = path.join(userDataPath, 'Settings'); | ||
return settingsFilePath; | ||
} | ||
@@ -72,4 +64,6 @@ | ||
if (!this._fsWatcher) { | ||
const settingsFilePath = this._getSettingsPath(); | ||
try { | ||
this._fsWatcher = fs.watch(this._settingsPath, this._handleSettingsChange); | ||
this._fsWatcher = fs.watch(settingsFilePath, this._handleSettingsChange); | ||
} catch(err) { | ||
@@ -89,4 +83,6 @@ // File may not exist yet or possible user permissions error. | ||
_writeSettings(obj={}, opts={}) { | ||
const settingsFilePath = this._getSettingsPath(); | ||
try { | ||
fs.outputJsonSync(this._settingsPath, obj, { | ||
fs.outputJsonSync(settingsFilePath, obj, { | ||
spaces: opts.prettify ? 2 : 0 | ||
@@ -108,4 +104,6 @@ }); | ||
_readSettings() { | ||
const settingsFilePath = this._getSettingsPath(); | ||
try { | ||
return fs.readJsonSync(this._settingsPath); | ||
return fs.readJsonSync(settingsFilePath); | ||
} catch(err) { | ||
@@ -112,0 +110,0 @@ this._writeSettings(); |
{ | ||
"name": "electron-settings", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "A simple persistent user settings manager for Electron.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21462
9
0
396