window controls overlay (windows&linux) (#1969)
Co-authored-by: julius <[email protected]>
This commit is contained in:
1 parent
96c9306dbd
commit
dff8784aef
10 files changed
+127
-10
No files matched your search
@@ -7,6 +7,7 @@ import * as Path from "node:path";
|
||||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
type BrowserWindowConstructorOptions,
|
||||
clipboard,
|
||||
dialog,
|
||||
ipcMain,
|
||||
@@ -118,6 +119,15 @@ const DESKTOP_UPDATE_CHANNEL = "latest";
|
||||
const DESKTOP_UPDATE_ALLOW_PRERELEASE = false;
|
||||
const DESKTOP_LOOPBACK_HOST = "127.0.0.1";
|
||||
const DESKTOP_REQUIRED_PORT_PROBE_HOSTS = ["0.0.0.0", "::"] as const;
|
||||
const TITLEBAR_HEIGHT = 40;
|
||||
const TITLEBAR_COLOR = "#01000000"; // #00000000 does not work correctly on Linux
|
||||
const TITLEBAR_LIGHT_SYMBOL_COLOR = "#1f2937";
|
||||
const TITLEBAR_DARK_SYMBOL_COLOR = "#f8fafc";
|
||||
|
||||
type WindowTitleBarOptions = Pick<
|
||||
BrowserWindowConstructorOptions,
|
||||
"titleBarOverlay" | "titleBarStyle" | "trafficLightPosition"
|
||||
>;
|
||||
|
||||
type DesktopUpdateErrorContext = DesktopUpdateState["errorContext"];
|
||||
type LinuxDesktopNamedApp = Electron.App & {
|
||||
@@ -1649,6 +1659,46 @@ function getInitialWindowBackgroundColor(): string {
|
||||
return nativeTheme.shouldUseDarkColors ? "#0a0a0a" : "#ffffff";
|
||||
}
|
||||
|
||||
function getWindowTitleBarOptions(): WindowTitleBarOptions {
|
||||
if (process.platform === "darwin") {
|
||||
return {
|
||||
titleBarStyle: "hiddenInset",
|
||||
trafficLightPosition: { x: 16, y: 18 },
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
titleBarStyle: "hidden",
|
||||
titleBarOverlay: {
|
||||
color: TITLEBAR_COLOR,
|
||||
height: TITLEBAR_HEIGHT,
|
||||
symbolColor: nativeTheme.shouldUseDarkColors
|
||||
? TITLEBAR_DARK_SYMBOL_COLOR
|
||||
: TITLEBAR_LIGHT_SYMBOL_COLOR,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function syncWindowAppearance(window: BrowserWindow): void {
|
||||
if (window.isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.setBackgroundColor(getInitialWindowBackgroundColor());
|
||||
const { titleBarOverlay } = getWindowTitleBarOptions();
|
||||
if (typeof titleBarOverlay === "object") {
|
||||
window.setTitleBarOverlay(titleBarOverlay);
|
||||
}
|
||||
}
|
||||
|
||||
function syncAllWindowAppearance(): void {
|
||||
for (const window of BrowserWindow.getAllWindows()) {
|
||||
syncWindowAppearance(window);
|
||||
}
|
||||
}
|
||||
|
||||
nativeTheme.on("updated", syncAllWindowAppearance);
|
||||
|
||||
function createWindow(): BrowserWindow {
|
||||
const window = new BrowserWindow({
|
||||
width: 1100,
|
||||
@@ -1660,8 +1710,7 @@ function createWindow(): BrowserWindow {
|
||||
backgroundColor: getInitialWindowBackgroundColor(),
|
||||
...getIconOption(),
|
||||
title: APP_DISPLAY_NAME,
|
||||
titleBarStyle: "hiddenInset",
|
||||
trafficLightPosition: { x: 16, y: 18 },
|
||||
...getWindowTitleBarOptions(),
|
||||
webPreferences: {
|
||||
preload: Path.join(__dirname, "preload.js"),
|
||||
contextIsolation: true,
|
||||
|
||||
@@ -313,6 +313,7 @@ type ChatViewProps =
|
||||
environmentId: EnvironmentId;
|
||||
threadId: ThreadId;
|
||||
onDiffPanelOpen?: () => void;
|
||||
reserveTitleBarControlInset?: boolean;
|
||||
routeKind: "server";
|
||||
draftId?: never;
|
||||
}
|
||||
@@ -320,6 +321,7 @@ type ChatViewProps =
|
||||
environmentId: EnvironmentId;
|
||||
threadId: ThreadId;
|
||||
onDiffPanelOpen?: () => void;
|
||||
reserveTitleBarControlInset?: boolean;
|
||||
routeKind: "draft";
|
||||
draftId: DraftId;
|
||||
};
|
||||
@@ -573,7 +575,13 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
|
||||
});
|
||||
|
||||
export default function ChatView(props: ChatViewProps) {
|
||||
const { environmentId, threadId, routeKind, onDiffPanelOpen } = props;
|
||||
const {
|
||||
environmentId,
|
||||
threadId,
|
||||
routeKind,
|
||||
onDiffPanelOpen,
|
||||
reserveTitleBarControlInset = true,
|
||||
} = props;
|
||||
const draftId = routeKind === "draft" ? props.draftId : null;
|
||||
const routeThreadRef = useMemo(
|
||||
() => scopeThreadRef(environmentId, threadId),
|
||||
@@ -3117,7 +3125,13 @@ export default function ChatView(props: ChatViewProps) {
|
||||
<header
|
||||
className={cn(
|
||||
"border-b border-border px-3 sm:px-5",
|
||||
isElectron ? "drag-region flex h-[52px] items-center" : "py-2 sm:py-3",
|
||||
isElectron
|
||||
? cn(
|
||||
"drag-region flex h-[52px] items-center wco:h-[env(titlebar-area-height)]",
|
||||
reserveTitleBarControlInset &&
|
||||
"wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]",
|
||||
)
|
||||
: "py-2 sm:py-3",
|
||||
)}
|
||||
>
|
||||
<ChatHeader
|
||||
|
||||
@@ -10,8 +10,10 @@ export type DiffPanelMode = "inline" | "sheet" | "sidebar";
|
||||
function getDiffPanelHeaderRowClassName(mode: DiffPanelMode) {
|
||||
const shouldUseDragRegion = isElectron && mode !== "sheet";
|
||||
return cn(
|
||||
"flex items-center justify-between gap-2 px-4",
|
||||
shouldUseDragRegion ? "drag-region h-[52px] border-b border-border" : "h-12",
|
||||
"flex items-center justify-between gap-2 px-4 wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]",
|
||||
shouldUseDragRegion
|
||||
? "drag-region h-[52px] border-b border-border wco:h-[env(titlebar-area-height)]"
|
||||
: "h-12 wco:max-h-[env(titlebar-area-height)]",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,15 @@ export function NoActiveThreadState() {
|
||||
<header
|
||||
className={cn(
|
||||
"border-b border-border px-3 sm:px-5",
|
||||
isElectron ? "drag-region flex h-[52px] items-center" : "py-2 sm:py-3",
|
||||
isElectron
|
||||
? "drag-region flex h-[52px] items-center wco:h-[env(titlebar-area-height)]"
|
||||
: "py-2 sm:py-3",
|
||||
)}
|
||||
>
|
||||
{isElectron ? (
|
||||
<span className="text-xs text-muted-foreground/50">No active thread</span>
|
||||
<span className="text-xs text-muted-foreground/50 wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]">
|
||||
No active thread
|
||||
</span>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<SidebarTrigger className="size-7 shrink-0 md:hidden" />
|
||||
|
||||
@@ -1974,7 +1974,7 @@ const SidebarChromeHeader = memo(function SidebarChromeHeader({
|
||||
);
|
||||
|
||||
return isElectron ? (
|
||||
<SidebarHeader className="drag-region h-[52px] flex-row items-center gap-2 px-4 py-0 pl-[90px]">
|
||||
<SidebarHeader className="drag-region h-[52px] flex-row items-center gap-2 px-4 py-0 pl-[90px] wco:h-[env(titlebar-area-height)] wco:pl-[calc(env(titlebar-area-x)+1em)]">
|
||||
{wordmark}
|
||||
</SidebarHeader>
|
||||
) : (
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
@custom-variant dark (&:is(.dark, .dark *));
|
||||
/* Window Controls Overlay: active when Electron exposes native titlebar control geometry. */
|
||||
@custom-variant wco (&:is(.wco, .wco *));
|
||||
|
||||
@theme inline {
|
||||
--animate-skeleton: skeleton 2s -1s infinite linear;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
const WCO_CLASS_NAME = "wco";
|
||||
|
||||
interface WindowControlsOverlayLike {
|
||||
readonly visible: boolean;
|
||||
addEventListener(type: "geometrychange", listener: EventListener): void;
|
||||
removeEventListener(type: "geometrychange", listener: EventListener): void;
|
||||
}
|
||||
|
||||
interface NavigatorWithWindowControlsOverlay extends Navigator {
|
||||
readonly windowControlsOverlay?: WindowControlsOverlayLike;
|
||||
}
|
||||
|
||||
function getWindowControlsOverlay(): WindowControlsOverlayLike | null {
|
||||
if (typeof navigator === "undefined") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (navigator as NavigatorWithWindowControlsOverlay).windowControlsOverlay ?? null;
|
||||
}
|
||||
|
||||
export function syncDocumentWindowControlsOverlayClass(): () => void {
|
||||
if (typeof document === "undefined") {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
const overlay = getWindowControlsOverlay();
|
||||
const update = () => {
|
||||
document.documentElement.classList.toggle(WCO_CLASS_NAME, overlay !== null && overlay.visible);
|
||||
};
|
||||
|
||||
update();
|
||||
if (!overlay) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
overlay.addEventListener("geometrychange", update);
|
||||
return () => {
|
||||
overlay.removeEventListener("geometrychange", update);
|
||||
};
|
||||
}
|
||||
@@ -9,12 +9,17 @@ import "./index.css";
|
||||
import { isElectron } from "./env";
|
||||
import { getRouter } from "./router";
|
||||
import { APP_DISPLAY_NAME } from "./branding";
|
||||
import { syncDocumentWindowControlsOverlayClass } from "./lib/windowControlsOverlay";
|
||||
|
||||
// Electron loads the app from a file-backed shell, so hash history avoids path resolution issues.
|
||||
const history = isElectron ? createHashHistory() : createBrowserHistory();
|
||||
|
||||
const router = getRouter(history);
|
||||
|
||||
if (isElectron) {
|
||||
syncDocumentWindowControlsOverlayClass();
|
||||
}
|
||||
|
||||
document.title = APP_DISPLAY_NAME;
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||
|
||||
@@ -269,6 +269,7 @@ function ChatThreadRouteView() {
|
||||
environmentId={threadRef.environmentId}
|
||||
threadId={threadRef.threadId}
|
||||
onDiffPanelOpen={markDiffOpened}
|
||||
reserveTitleBarControlInset={!diffOpen}
|
||||
routeKind="server"
|
||||
/>
|
||||
</SidebarInset>
|
||||
|
||||
@@ -56,7 +56,7 @@ function SettingsContentLayout() {
|
||||
)}
|
||||
|
||||
{isElectron && (
|
||||
<div className="drag-region flex h-[52px] shrink-0 items-center border-b border-border px-5">
|
||||
<div className="drag-region flex h-[52px] shrink-0 items-center border-b border-border px-5 wco:h-[env(titlebar-area-height)] wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]">
|
||||
<span className="text-xs font-medium tracking-wide text-muted-foreground/70">
|
||||
Settings
|
||||
</span>
|
||||
|
||||
Reference in new issue
Block a user