1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Hide windows controls behind the flags

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-12-07 16:14:34 +03:00
parent 9a263b82e2
commit a05c7a7124
2 changed files with 31 additions and 13 deletions

View File

@ -32,6 +32,13 @@ import logger from "./logger";
import { isWindows, productName } from "../common/vars"; import { isWindows, productName } from "../common/vars";
import { LensProxy } from "./lens-proxy"; 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 { function isHideable(window: BrowserWindow | null): boolean {
return Boolean(window && !window.isDestroyed()); return Boolean(window && !window.isDestroyed());
} }
@ -168,6 +175,11 @@ export class WindowManager extends Singleton {
ipcMainOn(IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, (event, clusterId: ClusterId) => { ipcMainOn(IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, (event, clusterId: ClusterId) => {
this.activeClusterId = 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<BrowserWindow> { async ensureMainWindow(showSplash = true): Promise<BrowserWindow> {

View File

@ -30,6 +30,8 @@ import { broadcastMessage, ipcRendererOn } from "../../../common/ipc";
import { watchHistoryState } from "../../remote-helpers/history-updater"; import { watchHistoryState } from "../../remote-helpers/history-updater";
import { isActiveRoute, navigate } from "../../navigation"; import { isActiveRoute, navigate } from "../../navigation";
import { catalogRoute, catalogURL } from "../../../common/routes"; import { catalogRoute, catalogURL } from "../../../common/routes";
import { IpcMainWindowEvents } from "../../../main/window-manager";
import { isLinux, isWindows } from "../../../common/vars";
interface Props extends React.HTMLAttributes<any> { interface Props extends React.HTMLAttributes<any> {
} }
@ -71,7 +73,7 @@ export const TopBar = observer(({ children, ...rest }: Props) => {
}; };
const openContextMenu = () => { const openContextMenu = () => {
broadcastMessage("show-app-context-menu"); broadcastMessage(IpcMainWindowEvents.OPEN_CONTEXT_MENU);
}; };
const goHome = () => { const goHome = () => {
@ -106,9 +108,11 @@ export const TopBar = observer(({ children, ...rest }: Props) => {
<div className={styles.topBar} {...rest}> <div className={styles.topBar} {...rest}>
<div className={styles.tools} onDoubleClick={windowSizeToggle}> <div className={styles.tools} onDoubleClick={windowSizeToggle}>
<div className={styles.winMenu}> <div className={styles.winMenu}>
<div onClick={openContextMenu}> {(isWindows || isLinux) && (
<svg width="12" height="12" viewBox="0 0 12 12"><path fill="currentColor" d="m1 10h10v1h-10z"/><path fill="currentColor" d="m1 5.5h10v1h-10z"/><path fill="currentColor" d="m1 1h10v1h-10z"/></svg> <div onClick={openContextMenu} data-testid="window-menu">
</div> <svg width="12" height="12" viewBox="0 0 12 12"><path fill="currentColor" d="m1 10h10v1h-10z"/><path fill="currentColor" d="m1 5.5h10v1h-10z"/><path fill="currentColor" d="m1 1h10v1h-10z"/></svg>
</div>
)}
</div> </div>
<Icon <Icon
data-testid="home-button" data-testid="home-button"
@ -135,16 +139,18 @@ export const TopBar = observer(({ children, ...rest }: Props) => {
<div className={styles.controls}> <div className={styles.controls}>
{renderRegisteredItems()} {renderRegisteredItems()}
{children} {children}
<div className={styles.winButtons}> {isWindows && (
<div className={styles.minimize}> <div className={styles.winButtons}>
<svg width="12" height="12" viewBox="0 0 12 12"><rect fill="currentColor" width="10" height="1" x="1" y="6"></rect></svg></div> <div className={styles.minimize} data-testid="window-minimize" onClick={() => broadcastMessage(IpcMainWindowEvents.MINIMIZE)}>
<div className={styles.maximize}> <svg width="12" height="12" viewBox="0 0 12 12"><rect fill="currentColor" width="10" height="1" x="1" y="6"></rect></svg></div>
<svg width="12" height="12" viewBox="0 0 12 12"><rect width="9" height="9" x="1.5" y="1.5" fill="none" stroke="currentColor"></rect></svg> <div className={styles.maximize} data-testid="window-maximize" onClick={() => broadcastMessage(IpcMainWindowEvents.MAXIMIZE)}>
<svg width="12" height="12" viewBox="0 0 12 12"><rect width="9" height="9" x="1.5" y="1.5" fill="none" stroke="currentColor"></rect></svg>
</div>
<div className={styles.close} data-testid="window-close" onClick={() => broadcastMessage(IpcMainWindowEvents.CLOSE)}>
<svg width="12" height="12" viewBox="0 0 12 12"><polygon fill="currentColor" points="11 1.576 6.583 6 11 10.424 10.424 11 6 6.583 1.576 11 1 10.424 5.417 6 1 1.576 1.576 1 6 5.417 10.424 1"></polygon></svg>
</div>
</div> </div>
<div className={styles.close}> )}
<svg width="12" height="12" viewBox="0 0 12 12"><polygon fill="currentColor" points="11 1.576 6.583 6 11 10.424 10.424 11 6 6.583 1.576 11 1 10.424 5.417 6 1 1.576 1.576 1 6 5.417 10.424 1"></polygon></svg>
</div>
</div>
</div> </div>
</div> </div>
); );