don't display fallback menu unless we've closed the last window

This commit is contained in:
SteVen Batten
2018-08-03 11:37:57 -07:00
parent 1e45ce6add
commit 1a1b92fbd0
3 changed files with 15 additions and 10 deletions

View File

@@ -31,12 +31,13 @@ export class Menubar {
private static readonly MAX_MENU_RECENT_ENTRIES = 10;
private isQuitting: boolean;
private appMenuInstalled: boolean;
private closedLastWindow: boolean;
private menuUpdater: RunOnceScheduler;
private nativeTabMenuItems: Electron.MenuItem[];
private menubarMenus: IMenubarData = {};
private menubarMenus: IMenubarData;
private keybindings: { [commandId: string]: IMenubarKeybinding };
@@ -54,6 +55,8 @@ export class Menubar {
this.keybindings = Object.create(null);
this.closedLastWindow = false;
this.install();
this.registerListeners();
@@ -149,9 +152,9 @@ export class Menubar {
return;
}
// Update menu if window count goes from N > 0 or 0 > N to update menu item enablement
if ((e.oldCount === 0 && e.newCount > 0) || (e.oldCount > 0 && e.newCount === 0)) {
this.closedLastWindow = e.newCount === 0;
this.scheduleUpdateMenu();
}
@@ -379,18 +382,22 @@ export class Menubar {
switch (menuId) {
case 'File':
case 'Window':
case 'Help':
if (isMacintosh) {
return this.windowsMainService.getWindowCount() === 0 || !!this.menubarMenus[menuId];
return (this.windowsMainService.getWindowCount() === 0 && this.closedLastWindow) || (!!this.menubarMenus && !!this.menubarMenus[menuId]);
}
break;
case 'Window':
if (isMacintosh) {
return (this.windowsMainService.getWindowCount() === 0 && this.closedLastWindow) || !!this.menubarMenus;
}
default:
return this.windowsMainService.getWindowCount() > 0 && !!this.menubarMenus[menuId];
return this.windowsMainService.getWindowCount() > 0 && (!!this.menubarMenus && !!this.menubarMenus[menuId]);
}
}
private shouldFallback(menuId: string): boolean {
return this.shouldDrawMenu(menuId) && (this.windowsMainService.getWindowCount() === 0 && isMacintosh);
return this.shouldDrawMenu(menuId) && (this.windowsMainService.getWindowCount() === 0 && this.closedLastWindow && isMacintosh);
}
private setFallbackMenuById(menu: Electron.Menu, menuId: string): void {
@@ -520,7 +527,7 @@ export class Menubar {
}
private setMenuById(menu: Electron.Menu, menuId: string): void {
if (this.menubarMenus[menuId]) {
if (this.menubarMenus && this.menubarMenus[menuId]) {
this.setMenu(menu, this.menubarMenus[menuId].items);
}
}