зеркало из https://github.com/electron/electron.git
Revert "Add systemPreferences.registerDefaults()"
This commit is contained in:
Родитель
19f1fef040
Коммит
1caa04c0bf
|
@ -65,7 +65,6 @@ void SystemPreferences::BuildPrototype(
|
|||
&SystemPreferences::SubscribeLocalNotification)
|
||||
.SetMethod("unsubscribeLocalNotification",
|
||||
&SystemPreferences::UnsubscribeLocalNotification)
|
||||
.SetMethod("registerDefaults", &SystemPreferences::RegisterDefaults)
|
||||
.SetMethod("getUserDefault", &SystemPreferences::GetUserDefault)
|
||||
.SetMethod("setUserDefault", &SystemPreferences::SetUserDefault)
|
||||
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
|
||||
|
|
|
@ -73,7 +73,6 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
|||
void UnsubscribeLocalNotification(int request_id);
|
||||
v8::Local<v8::Value> GetUserDefault(const std::string& name,
|
||||
const std::string& type);
|
||||
void RegisterDefaults(mate::Arguments* args);
|
||||
void SetUserDefault(const std::string& name,
|
||||
const std::string& type,
|
||||
mate::Arguments* args);
|
||||
|
|
|
@ -144,21 +144,6 @@ v8::Local<v8::Value> SystemPreferences::GetUserDefault(
|
|||
}
|
||||
}
|
||||
|
||||
void SystemPreferences::RegisterDefaults(mate::Arguments* args) {
|
||||
base::DictionaryValue value;
|
||||
|
||||
if(!args->GetNext(&value)) {
|
||||
args->ThrowError("Invalid userDefault data provided");
|
||||
} else {
|
||||
@try {
|
||||
NSDictionary* dict = DictionaryValueToNSDictionary(value);
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
||||
} @catch (NSException* exception) {
|
||||
args->ThrowError("Invalid userDefault data provided");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SystemPreferences::SetUserDefault(const std::string& name,
|
||||
const std::string& type,
|
||||
mate::Arguments* args) {
|
||||
|
|
|
@ -106,14 +106,6 @@ This is necessary for events such as `NSUserDefaultsDidChangeNotification`.
|
|||
|
||||
Same as `unsubscribeNotification`, but removes the subscriber from `NSNotificationCenter`.
|
||||
|
||||
### `systemPreferences.registerDefaults(defaults)` _macOS_
|
||||
|
||||
* `defaults` Object - a dictionary of (`key: value`) user defaults
|
||||
* `key` String
|
||||
* `value` Any
|
||||
|
||||
Add the specified defaults to your application's `NSUserDefaults`.
|
||||
|
||||
### `systemPreferences.getUserDefault(key, type)` _macOS_
|
||||
|
||||
* `key` String
|
||||
|
|
|
@ -35,44 +35,6 @@ describe('systemPreferences module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('systemPreferences.registerDefaults(defaults)', () => {
|
||||
before(function () {
|
||||
if (process.platform !== 'darwin') this.skip()
|
||||
})
|
||||
|
||||
it('registers defaults', () => {
|
||||
const defaultsMap = [
|
||||
{ key: 'one', type: 'string', value: 'ONE' },
|
||||
{ key: 'two', value: 2, type: 'integer' },
|
||||
{ key: 'three', value: [1, 2, 3], type: 'array' }
|
||||
]
|
||||
|
||||
const defaultsDict = {}
|
||||
defaultsMap.forEach(row => { defaultsDict[row.key] = row.value })
|
||||
|
||||
systemPreferences.registerDefaults(defaultsDict)
|
||||
|
||||
for (const userDefault of defaultsMap) {
|
||||
const { key, value: expectedValue, type } = userDefault
|
||||
const actualValue = systemPreferences.getUserDefault(key, type)
|
||||
assert.deepEqual(actualValue, expectedValue)
|
||||
}
|
||||
})
|
||||
|
||||
it('throws when bad defaults are passed', () => {
|
||||
for (const badDefaults of [
|
||||
{ 'one': null }, // catches null values
|
||||
1, // argument must be a dictionary
|
||||
null, // argument can't be null
|
||||
new Date() // shouldn't be able to pass date object
|
||||
]) {
|
||||
assert.throws(() => {
|
||||
systemPreferences.registerDefaults(badDefaults)
|
||||
}, 'Invalid userDefault data provided')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('systemPreferences.getUserDefault(key, type)', () => {
|
||||
before(function () {
|
||||
if (process.platform !== 'darwin') {
|
||||
|
|
Загрузка…
Ссылка в новой задаче