refactor: make applicationMenu a property on app (#17361)
This commit is contained in:
parent
d412582f72
commit
0431997c8d
4 changed files with 25 additions and 1 deletions
|
@ -1332,6 +1332,11 @@ Sets the `image` associated with this dock icon.
|
|||
|
||||
## Properties
|
||||
|
||||
### `app.applicationMenu`
|
||||
|
||||
A `Menu` property that return [`Menu`](menu.md) if one has been set and `null` otherwise.
|
||||
Users can pass a [Menu](menu.md) to set this property.
|
||||
|
||||
### `app.isPackaged`
|
||||
|
||||
A `Boolean` property that returns `true` if the app is packaged, `false` otherwise. For many apps, this property can be used to distinguish development and production environments.
|
||||
|
|
|
@ -19,9 +19,11 @@ Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
|
|||
EventEmitter.call(app as any)
|
||||
|
||||
Object.assign(app, {
|
||||
// TODO(codebytere): remove in 7.0
|
||||
setApplicationMenu (menu: Electron.Menu | null) {
|
||||
return Menu.setApplicationMenu(menu)
|
||||
},
|
||||
// TODO(codebytere): remove in 7.0
|
||||
getApplicationMenu () {
|
||||
return Menu.getApplicationMenu()
|
||||
},
|
||||
|
@ -38,6 +40,17 @@ Object.assign(app, {
|
|||
|
||||
app.getFileIcon = deprecate.promisify(app.getFileIcon)
|
||||
|
||||
// we define this here because it'd be overly complicated to
|
||||
// do in native land
|
||||
Object.defineProperty(app, 'applicationMenu', {
|
||||
get () {
|
||||
return Menu.getApplicationMenu()
|
||||
},
|
||||
set (menu: Electron.Menu | null) {
|
||||
return Menu.setApplicationMenu(menu)
|
||||
}
|
||||
})
|
||||
|
||||
app.isPackaged = (() => {
|
||||
const execFile = path.basename(process.execPath).toLowerCase()
|
||||
if (process.platform === 'win32') {
|
||||
|
|
|
@ -12,7 +12,7 @@ TopLevelWindow.prototype._init = function () {
|
|||
|
||||
// Simulate the application menu on platforms other than macOS.
|
||||
if (process.platform !== 'darwin') {
|
||||
const menu = app.getApplicationMenu()
|
||||
const menu = app.applicationMenu
|
||||
if (menu) this.setMenu(menu)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1232,6 +1232,12 @@ describe('app module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('app.applicationMenu', () => {
|
||||
it('has the applicationMenu property', () => {
|
||||
expect(app).to.have.property('applicationMenu')
|
||||
})
|
||||
})
|
||||
|
||||
describe('commandLine.hasSwitch', () => {
|
||||
it('returns true when present', () => {
|
||||
app.commandLine.appendSwitch('foobar1')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue