diff --git a/docs/api/app.md b/docs/api/app.md index 964b61613f..b542e0c63c 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -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. diff --git a/lib/browser/api/app.ts b/lib/browser/api/app.ts index 687420e37f..cfac9541f7 100644 --- a/lib/browser/api/app.ts +++ b/lib/browser/api/app.ts @@ -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') { diff --git a/lib/browser/api/top-level-window.js b/lib/browser/api/top-level-window.js index 36b0453319..b74ebf37a6 100644 --- a/lib/browser/api/top-level-window.js +++ b/lib/browser/api/top-level-window.js @@ -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) } } diff --git a/spec-main/api-app-spec.ts b/spec-main/api-app-spec.ts index 6e0e9ae80b..8a4458f633 100644 --- a/spec-main/api-app-spec.ts +++ b/spec-main/api-app-spec.ts @@ -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')