chore: update app module property support (#22747)

This commit is contained in:
Shelley Vohr
2020-03-20 00:09:47 -07:00
committed by GitHub
parent 54a8258c1c
commit dc25ad2ef0
5 changed files with 98 additions and 78 deletions

View File

@@ -1,7 +1,7 @@
import * as fs from 'fs'
import * as path from 'path'
import { deprecate, Menu } from 'electron'
import { Menu } from 'electron'
import { EventEmitter } from 'events'
const bindings = process.electronBinding('app')
@@ -17,6 +17,29 @@ let dockMenu: Electron.Menu | null = null
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
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, {
commandLine: {
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')
// Wrappers for native classes.
const { DownloadItem } = process.electronBinding('download_item')
Object.setPrototypeOf(DownloadItem.prototype, EventEmitter.prototype)