Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MacOS] Remove window focus listener on unload #11075

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
override onStart(app: FrontendApplication): void {
this.handleTitleBarStyling(app);
if (isOSX) {
// OSX: Recreate the menus when changing windows.
// OSX only has one menu bar for all windows, so we need to swap
// between them as the user switches windows.
electronRemote.getCurrentWindow().on('focus', () => this.setMenu(app));
this.attachWindowFocusListener(app);
}
// Make sure the application menu is complete, once the frontend application is ready.
// https://github.com/theia-ide/theia/issues/5100
Expand All @@ -125,6 +122,16 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
});
}

protected attachWindowFocusListener(app: FrontendApplication): void {
// OSX: Recreate the menus when changing windows.
// OSX only has one menu bar for all windows, so we need to swap
// between them as the user switches windows.
const targetWindow = electronRemote.getCurrentWindow();
const callback = () => this.setMenu(app);
targetWindow.on('focus', callback);
window.addEventListener('unload', () => targetWindow.off('focus', callback));
}

handleTitleBarStyling(app: FrontendApplication): void {
this.hideTopPanel(app);
electron.ipcRenderer.on(TitleBarStyleAtStartup, (_event, style: string) => {
Expand Down