From a05c7a7124535d3fb258cffb87b16ffda7d2a86f Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Tue, 7 Dec 2021 16:14:34 +0300 Subject: [PATCH] Hide windows controls behind the flags Signed-off-by: Alex Andreev --- src/main/window-manager.ts | 12 +++++++++ src/renderer/components/layout/topbar.tsx | 32 ++++++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index 47daf070bc..a082912820 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -32,6 +32,13 @@ import logger from "./logger"; import { isWindows, productName } from "../common/vars"; import { LensProxy } from "./lens-proxy"; +export const enum IpcMainWindowEvents { + MINIMIZE = "window:minimize", + MAXIMIZE = "window:maximize", + CLOSE = "window:close", + OPEN_CONTEXT_MENU = "window:open-context-menu", +} + function isHideable(window: BrowserWindow | null): boolean { return Boolean(window && !window.isDestroyed()); } @@ -168,6 +175,11 @@ export class WindowManager extends Singleton { ipcMainOn(IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, (event, clusterId: ClusterId) => { this.activeClusterId = clusterId; }); + + // custom window events, needed on windows and linux + ipcMainOn(IpcMainWindowEvents.MINIMIZE, () => this.mainWindow.minimize()); + ipcMainOn(IpcMainWindowEvents.MAXIMIZE, () => this.mainWindow.maximize()); + ipcMainOn(IpcMainWindowEvents.CLOSE, () => this.mainWindow.close()); } async ensureMainWindow(showSplash = true): Promise { diff --git a/src/renderer/components/layout/topbar.tsx b/src/renderer/components/layout/topbar.tsx index fe64438b74..7211fa92b9 100644 --- a/src/renderer/components/layout/topbar.tsx +++ b/src/renderer/components/layout/topbar.tsx @@ -30,6 +30,8 @@ import { broadcastMessage, ipcRendererOn } from "../../../common/ipc"; import { watchHistoryState } from "../../remote-helpers/history-updater"; import { isActiveRoute, navigate } from "../../navigation"; import { catalogRoute, catalogURL } from "../../../common/routes"; +import { IpcMainWindowEvents } from "../../../main/window-manager"; +import { isLinux, isWindows } from "../../../common/vars"; interface Props extends React.HTMLAttributes { } @@ -71,7 +73,7 @@ export const TopBar = observer(({ children, ...rest }: Props) => { }; const openContextMenu = () => { - broadcastMessage("show-app-context-menu"); + broadcastMessage(IpcMainWindowEvents.OPEN_CONTEXT_MENU); }; const goHome = () => { @@ -106,9 +108,11 @@ export const TopBar = observer(({ children, ...rest }: Props) => {
-
- -
+ {(isWindows || isLinux) && ( +
+ +
+ )}
{
{renderRegisteredItems()} {children} -
-
-
-
- + {isWindows && ( +
+
broadcastMessage(IpcMainWindowEvents.MINIMIZE)}> +
+
broadcastMessage(IpcMainWindowEvents.MAXIMIZE)}> + +
+
broadcastMessage(IpcMainWindowEvents.CLOSE)}> + +
-
- -
-
+ )}
);