diff --git a/src/main/app/windowManager.js b/src/main/app/windowManager.js index 572297c5..db320496 100644 --- a/src/main/app/windowManager.js +++ b/src/main/app/windowManager.js @@ -84,6 +84,12 @@ class WindowManager extends EventEmitter { */ add (window) { this._windows.set(window.id, window) + + if (!this._appMenu.has(window.id)) { + // TODO: Build a default menu for macOS. + this._appMenu.addMenu(window.id, null) + } + if (this.windowCount === 1) { this.setActiveWindow(window.id) } diff --git a/src/main/menu/index.js b/src/main/menu/index.js index 0af57f2d..d3659ec1 100644 --- a/src/main/menu/index.js +++ b/src/main/menu/index.js @@ -92,6 +92,11 @@ class AppMenu { fs.writeFileSync(RECENTS_PATH, json, 'utf-8') } + addMenu (windowId, menu=null) { + const { windowMenus } = this + windowMenus.set(windowId, { menu }) + } + addEditorMenu (window) { const { windowMenus } = this windowMenus.set(window.id, this.buildDefaultMenu(true)) @@ -126,12 +131,16 @@ class AppMenu { } getWindowMenuById (windowId) { - const { menu } = this.windowMenus.get(windowId) + const menu = this.windowMenus.get(windowId) if (!menu) { log.error(`getWindowMenuById: Cannot find window menu for id ${windowId}.`) throw new Error(`Cannot find window menu for id ${windowId}.`) } - return menu + return menu.menu + } + + has (windowId) { + return this.windowMenus.has(windowId) } setActiveWindow (windowId) {