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) {
|
||||
base::DictionaryValue value;
|
||||
if (!args->GetNext(&value)) {
|
||||
args->ThrowError("Unable to parse userDefaults dict");
|
||||
return;
|
||||
}
|
||||
|
||||
if (NSDictionary* dict = DictionaryValueToNSDictionary(value)) {
|
||||
args->GetNext(&value);
|
||||
|
||||
@try {
|
||||
NSDictionary* dict = DictionaryValueToNSDictionary(value);
|
||||
[[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_
|
||||
|
||||
* `defaults` Object - a dictionary of (`key: value`) user defaults
|
||||
* `key` String - must be of type `string`
|
||||
* `value` Object - object of type `string`, `boolean`, `integer`, `float`, `double`,
|
||||
* `key` String
|
||||
* `value` (String | Boolean | Number) - object of type `string`, `boolean`, `integer`, `float`, `double`,
|
||||
`url`, `array`, or `dictionary`.
|
||||
|
||||
Allows for registering of your application's preference defaults in `NSUserDefaults`.
|
||||
|
|
|
@ -42,25 +42,25 @@ describe('systemPreferences module', () => {
|
|||
|
||||
it('registers defaults', () => {
|
||||
const userDefaults = {
|
||||
'one': 'onee',
|
||||
'two': 'twoo',
|
||||
'three': 'threee',
|
||||
'four': 'fourr',
|
||||
'five': 'fivee'
|
||||
'one': 'ONE',
|
||||
'two': 'TWO',
|
||||
'three': 'THREE'
|
||||
}
|
||||
|
||||
systemPreferences.registerDefaults(userDefaults)
|
||||
|
||||
const val = systemPreferences.getUserDefault('two', 'string')
|
||||
assert.equal(val, 'twoo')
|
||||
for (const [key, expectedValue] of Object.entries(userDefaults)) {
|
||||
const actualValue = systemPreferences.getUserDefault(key, 'string')
|
||||
assert.equal(actualValue, expectedValue)
|
||||
}
|
||||
})
|
||||
|
||||
it('throws when bad defaults are passed', () => {
|
||||
const userDefaults = 1
|
||||
const badDefaults1 = { 'one': null }
|
||||
|
||||
assert.throws(() => {
|
||||
systemPreferences.setUserDefault(userDefaults)
|
||||
}, `Unable to parse userDefaults dict`)
|
||||
systemPreferences.registerDefaults(badDefaults1)
|
||||
}, 'Invalid userDefault data provided')
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue