use fallback menu (#1008)

This commit is contained in:
Felix Häusler 2019-05-07 16:17:58 +02:00 committed by Ran Luo
parent 68be52a87d
commit f45ec9d525
2 changed files with 17 additions and 2 deletions

View File

@ -84,6 +84,12 @@ class WindowManager extends EventEmitter {
*/ */
add (window) { add (window) {
this._windows.set(window.id, 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) { if (this.windowCount === 1) {
this.setActiveWindow(window.id) this.setActiveWindow(window.id)
} }

View File

@ -92,6 +92,11 @@ class AppMenu {
fs.writeFileSync(RECENTS_PATH, json, 'utf-8') fs.writeFileSync(RECENTS_PATH, json, 'utf-8')
} }
addMenu (windowId, menu=null) {
const { windowMenus } = this
windowMenus.set(windowId, { menu })
}
addEditorMenu (window) { addEditorMenu (window) {
const { windowMenus } = this const { windowMenus } = this
windowMenus.set(window.id, this.buildDefaultMenu(true)) windowMenus.set(window.id, this.buildDefaultMenu(true))
@ -126,12 +131,16 @@ class AppMenu {
} }
getWindowMenuById (windowId) { getWindowMenuById (windowId) {
const { menu } = this.windowMenus.get(windowId) const menu = this.windowMenus.get(windowId)
if (!menu) { if (!menu) {
log.error(`getWindowMenuById: Cannot find window menu for id ${windowId}.`) log.error(`getWindowMenuById: Cannot find window menu for id ${windowId}.`)
throw new Error(`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) { setActiveWindow (windowId) {