chore: update app module property support (#22713)
This commit is contained in:
parent
1ea21e42bb
commit
fc661ec56b
5 changed files with 97 additions and 77 deletions
|
@ -665,8 +665,6 @@ 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](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
### `app.setName(name)`
|
### `app.setName(name)`
|
||||||
|
|
||||||
* `name` String
|
* `name` String
|
||||||
|
@ -675,8 +673,6 @@ Overrides the current application's name.
|
||||||
|
|
||||||
**Note:** This function overrides the name used internally by Electron; it does not affect the name that the OS uses.
|
**Note:** This function overrides the name used internally by Electron; it does not affect the name that the OS uses.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
### `app.getLocale()`
|
### `app.getLocale()`
|
||||||
|
|
||||||
Returns `String` - The current application locale. Possible return values are documented [here](locales.md).
|
Returns `String` - The current application locale. Possible return values are documented [here](locales.md).
|
||||||
|
@ -1095,14 +1091,10 @@ 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](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](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
### `app.isUnityRunning()` _Linux_
|
### `app.isUnityRunning()` _Linux_
|
||||||
|
|
||||||
Returns `Boolean` - Whether the current desktop environment is Unity launcher.
|
Returns `Boolean` - Whether the current desktop environment is Unity launcher.
|
||||||
|
@ -1177,8 +1169,6 @@ 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](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
### `app.setAccessibilitySupportEnabled(enabled)` _macOS_ _Windows_
|
### `app.setAccessibilitySupportEnabled(enabled)` _macOS_ _Windows_
|
||||||
|
|
||||||
* `enabled` Boolean - Enable or disable [accessibility tree](https://developers.google.com/web/fundamentals/accessibility/semantics-builtin/the-accessibility-tree) rendering
|
* `enabled` Boolean - Enable or disable [accessibility tree](https://developers.google.com/web/fundamentals/accessibility/semantics-builtin/the-accessibility-tree) rendering
|
||||||
|
@ -1190,8 +1180,6 @@ 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](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
### `app.showAboutPanel()`
|
### `app.showAboutPanel()`
|
||||||
|
|
||||||
Show the app's about panel options. These options can be overridden with `app.setAboutPanelOptions(options)`.
|
Show the app's about panel options. These options can be overridden with `app.setAboutPanelOptions(options)`.
|
||||||
|
|
|
@ -45,9 +45,3 @@ The Electron team is currently undergoing an initiative to convert separate gett
|
||||||
* `isMacTemplateImage`
|
* `isMacTemplateImage`
|
||||||
* `SystemPreferences` module
|
* `SystemPreferences` module
|
||||||
* `appLevelAppearance`
|
* `appLevelAppearance`
|
||||||
* `webContents` module
|
|
||||||
* `audioMuted`
|
|
||||||
* `frameRate`
|
|
||||||
* `userAgent`
|
|
||||||
* `zoomFactor`
|
|
||||||
* `zoomLevel`
|
|
||||||
|
|
|
@ -17,6 +17,29 @@ let dockMenu: Electron.Menu | null = null
|
||||||
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
|
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
|
||||||
EventEmitter.call(app as any)
|
EventEmitter.call(app as any)
|
||||||
|
|
||||||
|
// Properties.
|
||||||
|
|
||||||
|
const nativeASGetter = app.isAccessibilitySupportEnabled
|
||||||
|
const nativeASSetter = app.setAccessibilitySupportEnabled
|
||||||
|
Object.defineProperty(App.prototype, 'accessibilitySupportEnabled', {
|
||||||
|
get: () => nativeASGetter.call(app),
|
||||||
|
set: (enabled) => nativeASSetter.call(app, enabled)
|
||||||
|
})
|
||||||
|
|
||||||
|
const nativeBCGetter = app.getBadgeCount
|
||||||
|
const nativeBCSetter = app.setBadgeCount
|
||||||
|
Object.defineProperty(App.prototype, 'badgeCount', {
|
||||||
|
get: () => nativeBCGetter.call(app),
|
||||||
|
set: (count) => nativeBCSetter.call(app, count)
|
||||||
|
})
|
||||||
|
|
||||||
|
const nativeNGetter = app.getName
|
||||||
|
const nativeNSetter = app.setName
|
||||||
|
Object.defineProperty(App.prototype, 'name', {
|
||||||
|
get: () => nativeNGetter.call(app),
|
||||||
|
set: (name) => nativeNSetter.call(app, name)
|
||||||
|
})
|
||||||
|
|
||||||
Object.assign(app, {
|
Object.assign(app, {
|
||||||
commandLine: {
|
commandLine: {
|
||||||
hasSwitch: (theSwitch: string) => commandLine.hasSwitch(String(theSwitch)),
|
hasSwitch: (theSwitch: string) => commandLine.hasSwitch(String(theSwitch)),
|
||||||
|
@ -112,11 +135,6 @@ for (const name of events) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Property Deprecations
|
|
||||||
deprecate.fnToProperty(App.prototype, 'accessibilitySupportEnabled', '_isAccessibilitySupportEnabled', '_setAccessibilitySupportEnabled')
|
|
||||||
deprecate.fnToProperty(App.prototype, 'badgeCount', '_getBadgeCount', '_setBadgeCount')
|
|
||||||
deprecate.fnToProperty(App.prototype, 'name', '_getName', '_setName')
|
|
||||||
|
|
||||||
// Deprecate allowRendererProcessReuse but only if they set it to false, no need to log if
|
// Deprecate allowRendererProcessReuse but only if they set it to false, no need to log if
|
||||||
// they are setting it to true
|
// they are setting it to true
|
||||||
deprecate.removeProperty(app, 'allowRendererProcessReuse', [false])
|
deprecate.removeProperty(app, 'allowRendererProcessReuse', [false])
|
||||||
|
|
|
@ -1413,8 +1413,8 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||||
base::BindRepeating(&Browser::GetVersion, browser))
|
base::BindRepeating(&Browser::GetVersion, browser))
|
||||||
.SetMethod("setVersion",
|
.SetMethod("setVersion",
|
||||||
base::BindRepeating(&Browser::SetVersion, browser))
|
base::BindRepeating(&Browser::SetVersion, browser))
|
||||||
.SetMethod("_getName", base::BindRepeating(&Browser::GetName, browser))
|
.SetMethod("getName", base::BindRepeating(&Browser::GetName, browser))
|
||||||
.SetMethod("_setName", base::BindRepeating(&Browser::SetName, browser))
|
.SetMethod("setName", base::BindRepeating(&Browser::SetName, browser))
|
||||||
.SetMethod("isReady", base::BindRepeating(&Browser::is_ready, browser))
|
.SetMethod("isReady", base::BindRepeating(&Browser::is_ready, browser))
|
||||||
.SetMethod("whenReady", base::BindRepeating(&Browser::WhenReady, browser))
|
.SetMethod("whenReady", base::BindRepeating(&Browser::WhenReady, browser))
|
||||||
.SetMethod("addRecentDocument",
|
.SetMethod("addRecentDocument",
|
||||||
|
@ -1435,20 +1435,15 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod(
|
.SetMethod(
|
||||||
"getApplicationNameForProtocol",
|
"getApplicationNameForProtocol",
|
||||||
base::BindRepeating(&Browser::GetApplicationNameForProtocol, browser))
|
base::BindRepeating(&Browser::GetApplicationNameForProtocol, browser))
|
||||||
.SetMethod("_setBadgeCount",
|
.SetMethod("setBadgeCount",
|
||||||
base::BindRepeating(&Browser::SetBadgeCount, browser))
|
base::BindRepeating(&Browser::SetBadgeCount, browser))
|
||||||
.SetMethod("_getBadgeCount",
|
.SetMethod("getBadgeCount",
|
||||||
base::BindRepeating(&Browser::GetBadgeCount, browser))
|
base::BindRepeating(&Browser::GetBadgeCount, browser))
|
||||||
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
|
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
|
||||||
.SetMethod("setLoginItemSettings",
|
.SetMethod("setLoginItemSettings",
|
||||||
base::BindRepeating(&Browser::SetLoginItemSettings, browser))
|
base::BindRepeating(&Browser::SetLoginItemSettings, browser))
|
||||||
.SetMethod("isEmojiPanelSupported",
|
.SetMethod("isEmojiPanelSupported",
|
||||||
base::BindRepeating(&Browser::IsEmojiPanelSupported, browser))
|
base::BindRepeating(&Browser::IsEmojiPanelSupported, browser))
|
||||||
.SetProperty("badgeCount",
|
|
||||||
base::BindRepeating(&Browser::GetBadgeCount, browser),
|
|
||||||
base::BindRepeating(&Browser::SetBadgeCount, browser))
|
|
||||||
.SetProperty("name", base::BindRepeating(&Browser::GetName, browser),
|
|
||||||
base::BindRepeating(&Browser::SetName, browser))
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
.SetMethod("hide", base::BindRepeating(&Browser::Hide, browser))
|
.SetMethod("hide", base::BindRepeating(&Browser::Hide, browser))
|
||||||
.SetMethod("show", base::BindRepeating(&Browser::Show, browser))
|
.SetMethod("show", base::BindRepeating(&Browser::Show, browser))
|
||||||
|
@ -1474,9 +1469,6 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||||
#if defined(OS_MACOSX) || defined(OS_WIN)
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
||||||
.SetMethod("showEmojiPanel",
|
.SetMethod("showEmojiPanel",
|
||||||
base::BindRepeating(&Browser::ShowEmojiPanel, browser))
|
base::BindRepeating(&Browser::ShowEmojiPanel, browser))
|
||||||
.SetProperty("accessibilitySupportEnabled",
|
|
||||||
&App::IsAccessibilitySupportEnabled,
|
|
||||||
&App::SetAccessibilitySupportEnabled)
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
.SetMethod("setUserTasks",
|
.SetMethod("setUserTasks",
|
||||||
|
@ -1503,9 +1495,9 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("requestSingleInstanceLock", &App::RequestSingleInstanceLock)
|
.SetMethod("requestSingleInstanceLock", &App::RequestSingleInstanceLock)
|
||||||
.SetMethod("releaseSingleInstanceLock", &App::ReleaseSingleInstanceLock)
|
.SetMethod("releaseSingleInstanceLock", &App::ReleaseSingleInstanceLock)
|
||||||
.SetMethod("relaunch", &App::Relaunch)
|
.SetMethod("relaunch", &App::Relaunch)
|
||||||
.SetMethod("_isAccessibilitySupportEnabled",
|
.SetMethod("isAccessibilitySupportEnabled",
|
||||||
&App::IsAccessibilitySupportEnabled)
|
&App::IsAccessibilitySupportEnabled)
|
||||||
.SetMethod("_setAccessibilitySupportEnabled",
|
.SetMethod("setAccessibilitySupportEnabled",
|
||||||
&App::SetAccessibilitySupportEnabled)
|
&App::SetAccessibilitySupportEnabled)
|
||||||
.SetMethod("disableHardwareAcceleration",
|
.SetMethod("disableHardwareAcceleration",
|
||||||
&App::DisableHardwareAcceleration)
|
&App::DisableHardwareAcceleration)
|
||||||
|
|
|
@ -83,35 +83,33 @@ describe('app module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.name', () => {
|
describe('app name APIs', () => {
|
||||||
it('returns the name field of package.json', () => {
|
it('with properties', () => {
|
||||||
expect(app.name).to.equal('Electron Test Main')
|
it('returns the name field of package.json', () => {
|
||||||
|
expect(app.name).to.equal('Electron Test Main')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('overrides the name', () => {
|
||||||
|
expect(app.name).to.equal('Electron Test Main')
|
||||||
|
app.name = 'test-name'
|
||||||
|
|
||||||
|
expect(app.name).to.equal('test-name')
|
||||||
|
app.name = 'Electron Test Main'
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('overrides the name', () => {
|
it('with functions', () => {
|
||||||
expect(app.name).to.equal('Electron Test Main')
|
it('returns the name field of package.json', () => {
|
||||||
app.name = 'test-name'
|
expect(app.getName()).to.equal('Electron Test Main')
|
||||||
|
})
|
||||||
|
|
||||||
expect(app.name).to.equal('test-name')
|
it('overrides the name', () => {
|
||||||
app.name = 'Electron Test Main'
|
expect(app.getName()).to.equal('Electron Test Main')
|
||||||
})
|
app.setName('test-name')
|
||||||
})
|
|
||||||
|
|
||||||
// TODO(codebytere): remove when propertyification is complete
|
expect(app.getName()).to.equal('test-name')
|
||||||
describe('app.getName()', () => {
|
app.setName('Electron Test Main')
|
||||||
it('returns the name field of package.json', () => {
|
})
|
||||||
expect(app.getName()).to.equal('Electron Test Main')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// TODO(codebytere): remove when propertyification is complete
|
|
||||||
describe('app.setName(name)', () => {
|
|
||||||
it('overrides the name', () => {
|
|
||||||
expect(app.getName()).to.equal('Electron Test Main')
|
|
||||||
app.setName('test-name')
|
|
||||||
|
|
||||||
expect(app.getName()).to.equal('test-name')
|
|
||||||
app.setName('Electron Test Main')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -554,20 +552,42 @@ describe('app module', () => {
|
||||||
after(() => { app.badgeCount = 0 })
|
after(() => { app.badgeCount = 0 })
|
||||||
|
|
||||||
describe('on supported platform', () => {
|
describe('on supported platform', () => {
|
||||||
it('sets a badge count', function () {
|
it('with properties', () => {
|
||||||
if (platformIsNotSupported) return this.skip()
|
it('sets a badge count', function () {
|
||||||
|
if (platformIsNotSupported) return this.skip()
|
||||||
|
|
||||||
app.badgeCount = expectedBadgeCount
|
app.badgeCount = expectedBadgeCount
|
||||||
expect(app.badgeCount).to.equal(expectedBadgeCount)
|
expect(app.badgeCount).to.equal(expectedBadgeCount)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('with functions', () => {
|
||||||
|
it('sets a badge count', function () {
|
||||||
|
if (platformIsNotSupported) return this.skip()
|
||||||
|
|
||||||
|
app.setBadgeCount(expectedBadgeCount)
|
||||||
|
expect(app.getBadgeCount()).to.equal(expectedBadgeCount)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('on unsupported platform', () => {
|
describe('on unsupported platform', () => {
|
||||||
it('does not set a badge count', function () {
|
it('with properties', () => {
|
||||||
if (platformIsSupported) return this.skip()
|
it('does not set a badge count', function () {
|
||||||
|
if (platformIsSupported) return this.skip()
|
||||||
|
|
||||||
app.badgeCount = 9999
|
app.badgeCount = 9999
|
||||||
expect(app.badgeCount).to.equal(0)
|
expect(app.badgeCount).to.equal(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('with functions', () => {
|
||||||
|
it('does not set a badge count)', function () {
|
||||||
|
if (platformIsSupported) return this.skip()
|
||||||
|
|
||||||
|
app.setBadgeCount(9999)
|
||||||
|
expect(app.getBadgeCount()).to.equal(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -655,15 +675,23 @@ describe('app module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('accessibilitySupportEnabled property', () => {
|
ifdescribe(process.platform !== 'linux')('accessibilitySupportEnabled property', () => {
|
||||||
if (process.platform === 'linux') return
|
it('with properties', () => {
|
||||||
|
it('can set accessibility support enabled', () => {
|
||||||
|
expect(app.accessibilitySupportEnabled).to.eql(false)
|
||||||
|
|
||||||
it('returns whether the Chrome has accessibility APIs enabled', () => {
|
app.accessibilitySupportEnabled = true
|
||||||
expect(app.accessibilitySupportEnabled).to.be.a('boolean')
|
expect(app.accessibilitySupportEnabled).to.eql(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// TODO(codebytere): remove when propertyification is complete
|
it('with functions', () => {
|
||||||
expect(app.isAccessibilitySupportEnabled).to.be.a('function')
|
it('can set accessibility support enabled', () => {
|
||||||
expect(app.setAccessibilitySupportEnabled).to.be.a('function')
|
expect(app.isAccessibilitySupportEnabled()).to.eql(false)
|
||||||
|
|
||||||
|
app.setAccessibilitySupportEnabled(true)
|
||||||
|
expect(app.isAccessibilitySupportEnabled()).to.eql(true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue