fixes from code review
This commit is contained in:
parent
5e51ab9791
commit
c5aeda1fdd
3 changed files with 18 additions and 18 deletions
|
@ -146,13 +146,13 @@ v8::Local<v8::Value> SystemPreferences::GetUserDefault(
|
||||||
|
|
||||||
void SystemPreferences::RegisterDefaults(mate::Arguments* args) {
|
void SystemPreferences::RegisterDefaults(mate::Arguments* args) {
|
||||||
base::DictionaryValue value;
|
base::DictionaryValue value;
|
||||||
if (!args->GetNext(&value)) {
|
args->GetNext(&value);
|
||||||
args->ThrowError("Unable to parse userDefaults dict");
|
|
||||||
return;
|
@try {
|
||||||
}
|
NSDictionary* dict = DictionaryValueToNSDictionary(value);
|
||||||
|
|
||||||
if (NSDictionary* dict = DictionaryValueToNSDictionary(value)) {
|
|
||||||
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
||||||
|
} @catch (NSException* exception) {
|
||||||
|
args->ThrowError("Invalid userDefault data provided");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,8 +109,8 @@ Same as `unsubscribeNotification`, but removes the subscriber from `NSNotificati
|
||||||
### `systemPreferences.registerDefaults(defaults)` _macOS_
|
### `systemPreferences.registerDefaults(defaults)` _macOS_
|
||||||
|
|
||||||
* `defaults` Object - a dictionary of (`key: value`) user defaults
|
* `defaults` Object - a dictionary of (`key: value`) user defaults
|
||||||
* `key` String - must be of type `string`
|
* `key` String
|
||||||
* `value` Object - object of type `string`, `boolean`, `integer`, `float`, `double`,
|
* `value` (String | Boolean | Number) - object of type `string`, `boolean`, `integer`, `float`, `double`,
|
||||||
`url`, `array`, or `dictionary`.
|
`url`, `array`, or `dictionary`.
|
||||||
|
|
||||||
Allows for registering of your application's preference defaults in `NSUserDefaults`.
|
Allows for registering of your application's preference defaults in `NSUserDefaults`.
|
||||||
|
|
|
@ -42,25 +42,25 @@ describe('systemPreferences module', () => {
|
||||||
|
|
||||||
it('registers defaults', () => {
|
it('registers defaults', () => {
|
||||||
const userDefaults = {
|
const userDefaults = {
|
||||||
'one': 'onee',
|
'one': 'ONE',
|
||||||
'two': 'twoo',
|
'two': 'TWO',
|
||||||
'three': 'threee',
|
'three': 'THREE'
|
||||||
'four': 'fourr',
|
|
||||||
'five': 'fivee'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
systemPreferences.registerDefaults(userDefaults)
|
systemPreferences.registerDefaults(userDefaults)
|
||||||
|
|
||||||
const val = systemPreferences.getUserDefault('two', 'string')
|
for (const [key, expectedValue] of Object.entries(userDefaults)) {
|
||||||
assert.equal(val, 'twoo')
|
const actualValue = systemPreferences.getUserDefault(key, 'string')
|
||||||
|
assert.equal(actualValue, expectedValue)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws when bad defaults are passed', () => {
|
it('throws when bad defaults are passed', () => {
|
||||||
const userDefaults = 1
|
const badDefaults1 = { 'one': null }
|
||||||
|
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
systemPreferences.setUserDefault(userDefaults)
|
systemPreferences.registerDefaults(badDefaults1)
|
||||||
}, `Unable to parse userDefaults dict`)
|
}, 'Invalid userDefault data provided')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue