[MM-38459] Resize the menu instead of removing the browser view altogether (#1730)

This commit is contained in:
Devin Binnie
2021-09-10 13:48:34 -04:00
committed by GitHub
parent 2bdc0dba2b
commit 20ec525819

View File

@@ -32,12 +32,14 @@ export default class TeamDropdownView {
expired?: Map<string, boolean>;
window: BrowserWindow;
windowBounds: Electron.Rectangle;
isOpen: boolean;
constructor(window: BrowserWindow, teams: TeamWithTabs[], darkMode: boolean, enableServerManagement: boolean) {
this.teams = teams;
this.window = window;
this.darkMode = darkMode;
this.enableServerManagement = enableServerManagement;
this.isOpen = false;
this.windowBounds = this.window.getContentBounds();
@@ -50,6 +52,7 @@ export default class TeamDropdownView {
}});
this.view.webContents.loadURL(getLocalURLString('dropdown.html'));
this.window.addBrowserView(this.view);
ipcMain.on(OPEN_TEAMS_DROPDOWN, this.handleOpen);
ipcMain.on(CLOSE_TEAMS_DROPDOWN, this.handleClose);
@@ -101,22 +104,27 @@ export default class TeamDropdownView {
}
handleOpen = () => {
this.window.addBrowserView(this.view);
const bounds = this.view.getBounds();
this.view.setBounds(this.getBounds(bounds.width, bounds.height));
if (!this.bounds) {
return;
}
this.view.setBounds(this.bounds);
this.window.setTopBrowserView(this.view);
this.view.webContents.focus();
WindowManager.sendToRenderer(OPEN_TEAMS_DROPDOWN);
this.isOpen = true;
}
handleClose = () => {
this.window.removeBrowserView(this.view);
this.view.setBounds(this.getBounds(0, 0));
WindowManager.sendToRenderer(CLOSE_TEAMS_DROPDOWN);
this.isOpen = false;
}
handleReceivedMenuSize = (event: IpcMainEvent, width: number, height: number) => {
const bounds = this.getBounds(width, height);
this.view.setBounds(bounds);
this.bounds = this.getBounds(width, height);
if (this.isOpen) {
this.view.setBounds(this.bounds);
}
}
getBounds = (width: number, height: number) => {