Custom title controls on Windows (#4528)

* Add context menu in topbar

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding windows title buttons

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding win sandwitch icon

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Hide windows controls behind the flags

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding tests

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fix topbar layout

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Using topbar as draggable area

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fix sandwich icon

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Mark no-draggable areas

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Remove ipcMainOn window calls

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fix tests

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Explicitly hide main window menu

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fix tests more

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Restore linux native view

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Not removing menu in linux

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Showing custom window buttons in Linux

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Remove frame on linux and windows

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Move open context menu event handler to initializers

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Set x, y context menu position explicitly

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev authored and GitHub committed 2021-12-14 19:01:57 +02:00
1 parent 1e22cffcd8
commit 637f26ae1e
9 files changed
+295 -29

No files matched your search

+15 -2
View File
@@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { BrowserWindow, dialog, IpcMainInvokeEvent } from "electron";
import { BrowserWindow, dialog, IpcMainInvokeEvent, Menu } from "electron";
import { clusterFrameMap } from "../../common/cluster-frames";
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterDeleteHandler, clusterSetDeletingHandler, clusterClearDeletingHandler } from "../../common/cluster-ipc";
import type { ClusterId } from "../../common/cluster-types";
@@ -30,10 +30,11 @@ import { catalogEntityRegistry } from "../catalog";
import { pushCatalogToRenderer } from "../catalog-pusher";
import { ClusterManager } from "../cluster-manager";
import { ResourceApplier } from "../resource-applier";
import { WindowManager } from "../window-manager";
import { IpcMainWindowEvents, WindowManager } from "../window-manager";
import path from "path";
import { remove } from "fs-extra";
import { AppPaths } from "../../common/app-paths";
import { getAppMenu } from "../menu";
export function initIpcMainHandlers() {
ipcMainHandle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
@@ -148,4 +149,16 @@ export function initIpcMainHandlers() {
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), dialogOpts);
});
ipcMainOn(IpcMainWindowEvents.OPEN_CONTEXT_MENU, async (event) => {
const menu = Menu.buildFromTemplate(getAppMenu(WindowManager.getInstance()));
const options = {
...BrowserWindow.fromWebContents(event.sender),
// Center of the topbar menu icon
x: 20,
y: 20,
} as Electron.PopupOptions;
menu.popup(options);
});
}
+7 -2
View File
@@ -61,7 +61,7 @@ export function showAbout(browserWindow: BrowserWindow) {
});
}
export function buildMenu(windowManager: WindowManager) {
export function getAppMenu(windowManager: WindowManager) {
function ignoreIf(check: boolean, menuItems: MenuItemConstructorOptions[]) {
return check ? [] : menuItems;
}
@@ -316,5 +316,10 @@ export function buildMenu(windowManager: WindowManager) {
appMenu.delete("mac");
}
Menu.setApplicationMenu(Menu.buildFromTemplate([...appMenu.values()]));
return [...appMenu.values()];
}
export function buildMenu(windowManager: WindowManager) {
Menu.setApplicationMenu(Menu.buildFromTemplate(getAppMenu(windowManager)));
}
+7 -2
View File
@@ -29,9 +29,13 @@ import { delay, iter, Singleton } from "../common/utils";
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
import logger from "./logger";
import { productName } from "../common/vars";
import { isMac, productName } from "../common/vars";
import { LensProxy } from "./lens-proxy";
export const enum IpcMainWindowEvents {
OPEN_CONTEXT_MENU = "window:open-context-menu",
}
function isHideable(window: BrowserWindow | null): boolean {
return Boolean(window && !window.isDestroyed());
}
@@ -81,7 +85,8 @@ export class WindowManager extends Singleton {
show: false,
minWidth: 700, // accommodate 800 x 600 display minimum
minHeight: 500, // accommodate 800 x 600 display minimum
titleBarStyle: "hiddenInset",
titleBarStyle: isMac ? "hiddenInset" : "hidden",
frame: isMac,
backgroundColor: "#1e2124",
webPreferences: {
nodeIntegration: true,