Add systemPreferences.setUserDefault for macOS
This API can be used to e.g. enable key repeat by setting `ApplePressAndHoldEnabled` to `false` (see also #47).
This commit is contained in:
parent
fb74f5576d
commit
486b6b9096
7 changed files with 169 additions and 11 deletions
|
@ -59,6 +59,47 @@ describe('systemPreferences module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('systemPreferences.setUserDefault(key, type, value)', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
return
|
||||
}
|
||||
|
||||
const KEY = 'SystemPreferencesTest'
|
||||
|
||||
const TEST_CASES = [
|
||||
['string', 'abc'],
|
||||
['boolean', true],
|
||||
['float', 2.5],
|
||||
['double', 10.1],
|
||||
['integer', 11],
|
||||
['url', 'https://github.com/electron'],
|
||||
['array', [1, 2, 3]],
|
||||
['dictionary', {'a': 1, 'b': 2}]
|
||||
]
|
||||
|
||||
it('sets values', () => {
|
||||
for (const [type, value] of TEST_CASES) {
|
||||
systemPreferences.setUserDefault(KEY, type, value)
|
||||
const retrievedValue = systemPreferences.getUserDefault(KEY, type)
|
||||
assert.deepEqual(retrievedValue, value)
|
||||
}
|
||||
})
|
||||
|
||||
it('throws when type and value conflict', () => {
|
||||
for (const [type, value] of TEST_CASES) {
|
||||
assert.throws(() => {
|
||||
systemPreferences.setUserDefault(KEY, type, typeof value === 'string' ? {} : 'foo')
|
||||
}, `Unable to convert value to: ${type}`)
|
||||
}
|
||||
})
|
||||
|
||||
it('throws when type is not valid', () => {
|
||||
assert.throws(() => {
|
||||
systemPreferences.setUserDefault(KEY, 'abc', 'foo')
|
||||
}, 'Invalid type: abc')
|
||||
})
|
||||
})
|
||||
|
||||
describe('systemPreferences.isInvertedColorScheme()', function () {
|
||||
it('returns a boolean', function () {
|
||||
assert.equal(typeof systemPreferences.isInvertedColorScheme(), 'boolean')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue