electron-settings
Advanced tools
Comparing version 4.0.2 to 5.0.0
@@ -5,2 +5,10 @@ # Changelog | ||
## [5.0.0](https://github.com/nathanbuchar/electron-settings/compare/v4.0.2...v5.0.0) (2023-04-20) | ||
### Features | ||
* drop electron.remote support ([#175](https://github.com/nathanbuchar/electron-settings/issues/175)) ([e956963](https://github.com/nathanbuchar/electron-settings/commit/e956963a0de5a3147886d3ba4aaa59ed5d30364c)) | ||
* Electron Settings v5 ([#177](https://github.com/nathanbuchar/electron-settings/issues/177)) ([59b50fd](https://github.com/nathanbuchar/electron-settings/commit/59b50fdb3a681e9ee1500f587d560e488064b0dd)) | ||
### [4.0.2](https://github.com/nathanbuchar/electron-settings/compare/v4.0.1...v4.0.2) (2020-06-27) | ||
@@ -7,0 +15,0 @@ |
@@ -55,3 +55,3 @@ /** | ||
*/ | ||
declare type KeyPath = string | Array<string | number>; | ||
type KeyPath = string | Array<string | number>; | ||
/** | ||
@@ -73,3 +73,3 @@ * `SettingsValue` types are the datatypes supported by | ||
*/ | ||
declare type SettingsValue = null | boolean | string | number | SettingsObject | SettingsValue[]; | ||
type SettingsValue = null | boolean | string | number | SettingsObject | SettingsValue[]; | ||
/** | ||
@@ -79,3 +79,3 @@ * A `SettingsObject` is an object whose property values | ||
*/ | ||
declare type SettingsObject = { | ||
type SettingsObject = { | ||
[key: string]: SettingsValue; | ||
@@ -88,3 +88,3 @@ }; | ||
*/ | ||
declare type Config = { | ||
type Config = { | ||
/** | ||
@@ -91,0 +91,0 @@ * Whether or not to save the settings file atomically. |
@@ -28,3 +28,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -53,7 +53,7 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
}; | ||
var electron_1 = __importDefault(require("electron")); | ||
var electron_1 = require("electron"); | ||
var fs_1 = __importDefault(require("fs")); | ||
var mkdirp_1 = __importDefault(require("mkdirp")); | ||
var path_1 = __importDefault(require("path")); | ||
var write_file_atomic_1 = __importDefault(require("write-file-atomic")); | ||
var atomically_1 = require("atomically"); | ||
var lodash_get_1 = __importDefault(require("lodash.get")); | ||
@@ -73,27 +73,8 @@ var lodash_has_1 = __importDefault(require("lodash.has")); | ||
/** | ||
* Returns the Electron instance. The developer may define | ||
* a custom Electron instance by using `configure()`. | ||
* | ||
* @returns The Electron instance. | ||
* @internal | ||
* Handle NodeJS error: https://stackoverflow.com/a/51525183/5522263 | ||
* @param error the error object. | ||
* @returns if given error object is a NodeJS error. | ||
*/ | ||
function getElectron() { | ||
var _a; | ||
return (_a = config.electron) !== null && _a !== void 0 ? _a : electron_1.default; | ||
} | ||
var isNodeError = function (error) { return error instanceof Error; }; | ||
/** | ||
* Returns the Electron app. The app may need be accessed | ||
* via `Remote` depending on whether this code is running | ||
* in the main or renderer process. | ||
* | ||
* @returns The Electron app. | ||
* @internal | ||
*/ | ||
function getElectronApp() { | ||
var _a; | ||
var e = getElectron(); | ||
var app = (_a = e.app) !== null && _a !== void 0 ? _a : e.remote.app; | ||
return app; | ||
} | ||
/** | ||
* Returns the path to the settings directory. The path | ||
@@ -108,3 +89,3 @@ * may be customized by the developer by using | ||
var _a; | ||
return (_a = config.dir) !== null && _a !== void 0 ? _a : getElectronApp().getPath('userData'); | ||
return (_a = config.dir) !== null && _a !== void 0 ? _a : electron_1.app.getPath('userData'); | ||
} | ||
@@ -134,3 +115,3 @@ /** | ||
if (err) { | ||
if (err.code === 'ENOENT') { | ||
if (isNodeError(err) && err.code === 'ENOENT') { | ||
saveSettings({}).then(resolve, reject); | ||
@@ -161,3 +142,3 @@ } | ||
if (err) { | ||
if (err.code === 'ENOENT') { | ||
if (isNodeError(err) && err.code === 'ENOENT') { | ||
saveSettingsSync({}); | ||
@@ -184,3 +165,3 @@ } | ||
if (err.code === 'ENOENT') { | ||
mkdirp_1.default(dirPath).then(function () { return resolve(); }, reject); | ||
(0, mkdirp_1.default)(dirPath).then(function () { return resolve(); }, reject); | ||
} | ||
@@ -209,3 +190,3 @@ else { | ||
catch (err) { | ||
if (err.code === 'ENOENT') { | ||
if (isNodeError(err) && err.code === 'ENOENT') { | ||
mkdirp_1.default.sync(dirPath); | ||
@@ -272,3 +253,3 @@ } | ||
if (config.atomicSave) { | ||
write_file_atomic_1.default(filePath, data, function (err) { | ||
(0, atomically_1.writeFile)(filePath, data, function (err) { | ||
return err | ||
@@ -301,3 +282,3 @@ ? reject(err) | ||
if (config.atomicSave) { | ||
write_file_atomic_1.default.sync(filePath, data); | ||
(0, atomically_1.writeFileSync)(filePath, data); | ||
} | ||
@@ -424,3 +405,3 @@ else { | ||
obj = _a.sent(); | ||
return [2 /*return*/, lodash_has_1.default(obj, keyPath)]; | ||
return [2 /*return*/, (0, lodash_has_1.default)(obj, keyPath)]; | ||
} | ||
@@ -473,3 +454,3 @@ }); | ||
var obj = loadSettingsSync(); | ||
return lodash_has_1.default(obj, keyPath); | ||
return (0, lodash_has_1.default)(obj, keyPath); | ||
} | ||
@@ -485,3 +466,3 @@ function get(keyPath) { | ||
if (keyPath) { | ||
return [2 /*return*/, lodash_get_1.default(obj, keyPath)]; | ||
return [2 /*return*/, (0, lodash_get_1.default)(obj, keyPath)]; | ||
} | ||
@@ -499,3 +480,3 @@ else { | ||
if (keyPath) { | ||
return lodash_get_1.default(obj, keyPath); | ||
return (0, lodash_get_1.default)(obj, keyPath); | ||
} | ||
@@ -524,3 +505,3 @@ else { | ||
obj = _a.sent(); | ||
lodash_set_1.default(obj, keyPath, value); | ||
(0, lodash_set_1.default)(obj, keyPath, value); | ||
return [2 /*return*/, saveSettings(obj)]; | ||
@@ -543,3 +524,3 @@ } | ||
var obj = loadSettingsSync(); | ||
lodash_set_1.default(obj, keyPath, value); | ||
(0, lodash_set_1.default)(obj, keyPath, value); | ||
saveSettingsSync(obj); | ||
@@ -558,3 +539,3 @@ } | ||
obj = _a.sent(); | ||
lodash_unset_1.default(obj, keyPath); | ||
(0, lodash_unset_1.default)(obj, keyPath); | ||
return [2 /*return*/, saveSettings(obj)]; | ||
@@ -571,3 +552,3 @@ case 2: | ||
var obj = loadSettingsSync(); | ||
lodash_unset_1.default(obj, keyPath); | ||
(0, lodash_unset_1.default)(obj, keyPath); | ||
saveSettingsSync(obj); | ||
@@ -574,0 +555,0 @@ } |
{ | ||
"name": "electron-settings", | ||
"version": "4.0.2", | ||
"version": "5.0.0", | ||
"description": "A simple and robust settings management library for Electron.", | ||
@@ -39,2 +39,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"atomically": "^2.0.1", | ||
"lodash.get": "^4.4.2", | ||
@@ -44,29 +45,27 @@ "lodash.has": "^4.5.2", | ||
"lodash.unset": "^4.5.2", | ||
"mkdirp": "^1.0.4", | ||
"write-file-atomic": "^3.0.3" | ||
"mkdirp": "^1.0.4" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash.get": "^4.4.6", | ||
"@types/lodash.has": "^4.5.6", | ||
"@types/lodash.set": "^4.3.6", | ||
"@types/lodash.unset": "^4.5.6", | ||
"@types/mkdirp": "^1.0.0", | ||
"@types/lodash.get": "^4.4.7", | ||
"@types/lodash.has": "^4.5.7", | ||
"@types/lodash.set": "^4.3.7", | ||
"@types/lodash.unset": "^4.5.7", | ||
"@types/mkdirp": "^1.0.2", | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^14.0.5", | ||
"@types/randomstring": "^1.1.6", | ||
"@types/rimraf": "^3.0.0", | ||
"@types/write-file-atomic": "^3.0.0", | ||
"@typescript-eslint/eslint-plugin": "^3.0.0", | ||
"@typescript-eslint/parser": "^3.0.0", | ||
"electron": "^9.0.0", | ||
"@types/node": "^14.18.42", | ||
"@types/randomstring": "^1.1.8", | ||
"@types/rimraf": "^3.0.2", | ||
"@typescript-eslint/eslint-plugin": "^3.10.1", | ||
"@typescript-eslint/parser": "^3.10.1", | ||
"electron": "^24.1.2", | ||
"electron-mocha": "^8.2.2", | ||
"eslint": "^7.1.0", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"randomstring": "^1.1.5", | ||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-plugin-import": "^2.27.5", | ||
"randomstring": "^1.2.3", | ||
"rimraf": "^3.0.2", | ||
"standard-version": "^8.0.0", | ||
"ts-node": "^8.10.1", | ||
"typedoc": "^0.17.7", | ||
"typescript": "^3.9.3" | ||
"ts-node": "^8.10.2", | ||
"typedoc": "^0.24.4", | ||
"typescript": "^4.9.5" | ||
}, | ||
@@ -73,0 +72,0 @@ "peerDependencies": { |
@@ -40,2 +40,14 @@ # Electron Settings | ||
`electron-settings` only works in the main process. If you want to use `electron-settings` in the renderer process, you need to use [IPC](https://www.electronjs.org/docs/api/ipc-main#ipcmainhandlechannel-listener). | ||
```js | ||
// main process | ||
ipcMain.handle('getSettingValue', (event, key) => { | ||
return settings.get(key); | ||
}); | ||
// renderer-process | ||
const foo = await ipcRenderer.invoke('getSettingValue', 'foo'); | ||
``` | ||
### API Docs | ||
@@ -42,0 +54,0 @@ |
Sorry, the diff of this file is not supported yet
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
49335
22
80
1152
+ Addedatomically@^2.0.1
+ Addedatomically@2.0.3(transitive)
+ Addedstubborn-fs@1.2.5(transitive)
+ Addedwhen-exit@2.1.3(transitive)
- Removedwrite-file-atomic@^3.0.3
- Removedimurmurhash@0.1.4(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedtypedarray-to-buffer@3.1.5(transitive)
- Removedwrite-file-atomic@3.0.3(transitive)