refactor: set appLevelAppearance prop on systemPreferences (#18477)

* refactor: set appLevelAppearance prop on systemPreferences

* ensure backwards compat is tested
This commit is contained in:
Shelley Vohr 2019-05-30 17:12:46 -07:00 committed by GitHub
parent ac35f41e8d
commit 1e3e5a6619
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 10 deletions

View file

@ -106,6 +106,9 @@ void SystemPreferences::BuildPrototype(
&SystemPreferences::GetAppLevelAppearance) &SystemPreferences::GetAppLevelAppearance)
.SetMethod("setAppLevelAppearance", .SetMethod("setAppLevelAppearance",
&SystemPreferences::SetAppLevelAppearance) &SystemPreferences::SetAppLevelAppearance)
.SetProperty("appLevelAppearance",
&SystemPreferences::GetAppLevelAppearance,
&SystemPreferences::SetAppLevelAppearance)
.SetMethod("getSystemColor", &SystemPreferences::GetSystemColor) .SetMethod("getSystemColor", &SystemPreferences::GetSystemColor)
.SetMethod("canPromptTouchID", &SystemPreferences::CanPromptTouchID) .SetMethod("canPromptTouchID", &SystemPreferences::CanPromptTouchID)
.SetMethod("promptTouchID", &SystemPreferences::PromptTouchID) .SetMethod("promptTouchID", &SystemPreferences::PromptTouchID)

View file

@ -667,7 +667,7 @@ to the npm modules spec. You should usually also specify a `productName`
field, which is your application's full capitalized name, and which will be field, which is your application's full capitalized name, and which will be
preferred over `name` by Electron. preferred over `name` by Electron.
**[Deprecated Soon](modernization/property-updates.md)** **[Deprecated](modernization/property-updates.md)**
### `app.setName(name)` ### `app.setName(name)`
@ -675,7 +675,7 @@ preferred over `name` by Electron.
Overrides the current application's name. Overrides the current application's name.
**[Deprecated Soon](modernization/property-updates.md)** **[Deprecated](modernization/property-updates.md)**
### `app.getLocale()` ### `app.getLocale()`
@ -1070,13 +1070,13 @@ On macOS, it shows on the dock icon. On Linux, it only works for Unity launcher.
**Note:** Unity launcher requires the existence of a `.desktop` file to work, **Note:** Unity launcher requires the existence of a `.desktop` file to work,
for more information please read [Desktop Environment Integration][unity-requirement]. for more information please read [Desktop Environment Integration][unity-requirement].
**[Deprecated Soon](modernization/property-updates.md)** **[Deprecated](modernization/property-updates.md)**
### `app.getBadgeCount()` _Linux_ _macOS_ ### `app.getBadgeCount()` _Linux_ _macOS_
Returns `Integer` - The current value displayed in the counter badge. Returns `Integer` - The current value displayed in the counter badge.
**[Deprecated Soon](modernization/property-updates.md)** **[Deprecated](modernization/property-updates.md)**
### `app.isUnityRunning()` _Linux_ ### `app.isUnityRunning()` _Linux_
@ -1152,7 +1152,7 @@ technologies, such as screen readers, has been detected. See
https://www.chromium.org/developers/design-documents/accessibility for more https://www.chromium.org/developers/design-documents/accessibility for more
details. details.
**[Deprecated Soon](modernization/property-updates.md)** **[Deprecated](modernization/property-updates.md)**
### `app.setAccessibilitySupportEnabled(enabled)` _macOS_ _Windows_ ### `app.setAccessibilitySupportEnabled(enabled)` _macOS_ _Windows_
@ -1165,7 +1165,7 @@ This API must be called after the `ready` event is emitted.
**Note:** Rendering accessibility tree can significantly affect the performance of your app. It should not be enabled by default. **Note:** Rendering accessibility tree can significantly affect the performance of your app. It should not be enabled by default.
**[Deprecated Soon](modernization/property-updates.md)** **[Deprecated](modernization/property-updates.md)**
### `app.showAboutPanel()` _macOS_ _Linux_ ### `app.showAboutPanel()` _macOS_ _Linux_

View file

@ -32,8 +32,6 @@ The Electron team is currently undergoing an initiative to convert separate gett
* `paused` * `paused`
* `Session` module * `Session` module
* `preloads` * `preloads`
* `SystemPreferences` module
* `appLevelAppearance`
* `webContents` module * `webContents` module
* `zoomFactor` * `zoomFactor`
* `zoomLevel` * `zoomLevel`
@ -58,3 +56,5 @@ The Electron team is currently undergoing an initiative to convert separate gett
* `name` * `name`
* `NativeImage` * `NativeImage`
* `isMacTemplateImage` * `isMacTemplateImage`
* `SystemPreferences` module
* `appLevelAppearance`

View file

@ -275,13 +275,13 @@ Returns [`Size`](structures/size.md)
Marks the image as a template image. Marks the image as a template image.
**[Deprecated Soon](modernization/property-updates.md)** **[Deprecated](modernization/property-updates.md)**
#### `image.isTemplateImage()` #### `image.isTemplateImage()`
Returns `Boolean` - Whether the image is a template image. Returns `Boolean` - Whether the image is a template image.
**[Deprecated Soon](modernization/property-updates.md)** **[Deprecated](modernization/property-updates.md)**
#### `image.crop(rect)` #### `image.crop(rect)`

View file

@ -380,12 +380,16 @@ You can use the `setAppLevelAppearance` API to set this value.
Sets the appearance setting for your application, this should override the Sets the appearance setting for your application, this should override the
system default and override the value of `getEffectiveAppearance`. system default and override the value of `getEffectiveAppearance`.
**[Deprecated](modernization/property-updates.md)**
### `systemPreferences.canPromptTouchID()` _macOS_ ### `systemPreferences.canPromptTouchID()` _macOS_
Returns `Boolean` - whether or not this device has the ability to use Touch ID. Returns `Boolean` - whether or not this device has the ability to use Touch ID.
**NOTE:** This API will return `false` on macOS systems older than Sierra 10.12.2. **NOTE:** This API will return `false` on macOS systems older than Sierra 10.12.2.
**[Deprecated](modernization/property-updates.md)**
### `systemPreferences.promptTouchID(reason)` _macOS_ ### `systemPreferences.promptTouchID(reason)` _macOS_
* `reason` String - The reason you are asking for Touch ID authentication * `reason` String - The reason you are asking for Touch ID authentication
@ -439,3 +443,13 @@ Returns `Object`:
* `prefersReducedMotion` Boolean - Determines whether the user desires reduced motion based on platform APIs. * `prefersReducedMotion` Boolean - Determines whether the user desires reduced motion based on platform APIs.
Returns an object with system animation settings. Returns an object with system animation settings.
## Properties
### `systemPreferences.appLevelAppearance` _macOS_
A `String` property that determines the macOS appearance setting for
your application. This maps to values in: [NSApplication.appearance](https://developer.apple.com/documentation/appkit/nsapplication/2967170-appearance?language=objc). Setting this will override the
system default as well as the value of `getEffectiveAppearance`.
Possible values that can be set are `dark` and `light`, and possible return values are `dark`, `light`, and `unknown`.

View file

@ -1,10 +1,15 @@
'use strict' 'use strict'
const { EventEmitter } = require('events') const { EventEmitter } = require('events')
const { deprecate } = require('electron')
const { systemPreferences, SystemPreferences } = process.electronBinding('system_preferences') const { systemPreferences, SystemPreferences } = process.electronBinding('system_preferences')
// SystemPreferences is an EventEmitter. // SystemPreferences is an EventEmitter.
Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype) Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype)
EventEmitter.call(systemPreferences) EventEmitter.call(systemPreferences)
if ('appLevelAppearance' in systemPreferences) {
deprecate.fnToProperty(systemPreferences, 'appLevelAppearance', '_getAppLevelAppearance', '_setAppLevelAppearance')
}
module.exports = systemPreferences module.exports = systemPreferences

View file

@ -151,6 +151,20 @@ describe('systemPreferences module', () => {
}) })
}) })
describe('systemPreferences.appLevelAppearance', () => {
before(function () {
if (process.platform !== 'darwin') this.skip()
})
it('has an appLevelAppearance property', () => {
expect(systemPreferences).to.have.a.property('appLevelAppearance')
// TODO(codebytere): remove when propertyification is complete
expect(systemPreferences.getAppLevelAppearance).to.be.a('function')
expect(systemPreferences.setAppLevelAppearance).to.be.a('function')
})
})
describe('systemPreferences.setUserDefault(key, type, value)', () => { describe('systemPreferences.setUserDefault(key, type, value)', () => {
before(function () { before(function () {
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {