Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sbatten authored and gjsjohnmurray committed Jul 8, 2020
1 parent fe6be23 commit b03264a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/vs/platform/menubar/electron-main/menubar.ts
Expand Up @@ -49,6 +49,7 @@ export class Menubar {
private willShutdown: boolean | undefined;
private appMenuInstalled: boolean | undefined;
private closedLastWindow: boolean;
private noActiveWindow: boolean;

private menuUpdater: RunOnceScheduler;
private menuGC: RunOnceScheduler;
Expand Down Expand Up @@ -89,6 +90,7 @@ export class Menubar {
this.addFallbackHandlers();

this.closedLastWindow = false;
this.noActiveWindow = false;

this.oldMenus = [];

Expand Down Expand Up @@ -168,6 +170,8 @@ export class Menubar {

// // Listen to some events from window service to update menu
this.windowsMainService.onWindowsCountChanged(e => this.onWindowsCountChanged(e));
this.electronMainService.onWindowBlur(() => this.onWindowFocusChange());
this.electronMainService.onWindowFocus(() => this.onWindowFocusChange());
}

private get currentEnableMenuBarMnemonics(): boolean {
Expand Down Expand Up @@ -234,6 +238,15 @@ export class Menubar {
}
}

private onWindowFocusChange(): void {
if (!isMacintosh) {
return;
}

this.noActiveWindow = !BrowserWindow.getFocusedWindow();
this.scheduleUpdateMenu();
}

private install(): void {
// Store old menu in our array to avoid GC to collect the menu and crash. See #55347
// TODO@sbatten Remove this when fixed upstream by Electron
Expand Down Expand Up @@ -412,12 +425,12 @@ export class Menubar {
case 'File':
case 'Help':
if (isMacintosh) {
return (this.windowsMainService.getWindowCount() === 0 && this.closedLastWindow) || (!!this.menubarMenus && !!this.menubarMenus[menuId]);
return (this.windowsMainService.getWindowCount() === 0 && this.closedLastWindow) || (this.windowsMainService.getWindowCount() > 0 && this.noActiveWindow) || (!!this.menubarMenus && !!this.menubarMenus[menuId]);
}

case 'Window':
if (isMacintosh) {
return (this.windowsMainService.getWindowCount() === 0 && this.closedLastWindow) || !!this.menubarMenus;
return (this.windowsMainService.getWindowCount() === 0 && this.closedLastWindow) || (this.windowsMainService.getWindowCount() > 0 && this.noActiveWindow) || !!this.menubarMenus;
}

default:
Expand All @@ -443,7 +456,8 @@ export class Menubar {
}

if (isMacintosh) {
if (this.windowsMainService.getWindowCount() === 0 && this.closedLastWindow) {
if ((this.windowsMainService.getWindowCount() === 0 && this.closedLastWindow) ||
(this.windowsMainService.getWindowCount() > 0 && this.noActiveWindow)) {
// In the fallback scenario, we are either disabled or using a fallback handler
if (this.fallbackMenuHandlers[item.id]) {
menu.append(new MenuItem(this.likeAction(item.id, { label: this.mnemonicLabel(item.label), click: this.fallbackMenuHandlers[item.id] })));
Expand Down

0 comments on commit b03264a

Please sign in to comment.