Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const PICK_FOLDER_CHANNEL = "desktop:pick-folder";
const CONFIRM_CHANNEL = "desktop:confirm";
const SET_THEME_CHANNEL = "desktop:set-theme";
const SET_SIDEBAR_OPACITY_CHANNEL = "desktop:set-sidebar-opacity";
const SET_WINDOW_BUTTON_VISIBILITY_CHANNEL = "desktop:set-window-button-visibility";
const CONTEXT_MENU_CHANNEL = "desktop:context-menu";
const OPEN_EXTERNAL_CHANNEL = "desktop:open-external";
const MENU_ACTION_CHANNEL = "desktop:menu-action";
Expand Down Expand Up @@ -1173,6 +1174,21 @@ function registerIpcHandlers(): void {
// applies the value through a CSS custom-property.
});

ipcMain.removeHandler(SET_WINDOW_BUTTON_VISIBILITY_CHANNEL);
ipcMain.handle(SET_WINDOW_BUTTON_VISIBILITY_CHANNEL, async (event, rawVisible: unknown) => {
if (process.platform !== "darwin" || typeof rawVisible !== "boolean") {
return;
}

const owner =
BrowserWindow.fromWebContents(event.sender) ?? BrowserWindow.getFocusedWindow() ?? mainWindow;
if (!owner || owner.isDestroyed()) {
return;
}

owner.setWindowButtonVisibility(rawVisible);
});

ipcMain.removeHandler(CONTEXT_MENU_CHANNEL);
ipcMain.handle(
CONTEXT_MENU_CHANNEL,
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const PICK_FOLDER_CHANNEL = "desktop:pick-folder";
const CONFIRM_CHANNEL = "desktop:confirm";
const SET_THEME_CHANNEL = "desktop:set-theme";
const SET_SIDEBAR_OPACITY_CHANNEL = "desktop:set-sidebar-opacity";
const SET_WINDOW_BUTTON_VISIBILITY_CHANNEL = "desktop:set-window-button-visibility";
const CONTEXT_MENU_CHANNEL = "desktop:context-menu";
const OPEN_EXTERNAL_CHANNEL = "desktop:open-external";
const MENU_ACTION_CHANNEL = "desktop:menu-action";
Expand Down Expand Up @@ -37,6 +38,8 @@ contextBridge.exposeInMainWorld("desktopBridge", {
confirm: (message) => ipcRenderer.invoke(CONFIRM_CHANNEL, message),
setTheme: (theme) => ipcRenderer.invoke(SET_THEME_CHANNEL, theme),
setSidebarOpacity: (opacity) => ipcRenderer.invoke(SET_SIDEBAR_OPACITY_CHANNEL, opacity),
setWindowButtonVisibility: (visible) =>
ipcRenderer.invoke(SET_WINDOW_BUTTON_VISIBILITY_CHANNEL, visible),
showContextMenu: (items, position) => ipcRenderer.invoke(CONTEXT_MENU_CHANNEL, items, position),
openExternal: (url: string) => ipcRenderer.invoke(OPEN_EXTERNAL_CHANNEL, url),
onMenuAction: (listener) => {
Expand Down
4 changes: 1 addition & 3 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4700,9 +4700,7 @@ export default function ChatView({ threadId, onMinimize }: ChatViewProps) {
<header
className={cn(
"border-b border-border px-3 sm:px-5",
isElectron
? "drag-region flex h-[52px] items-center pl-[90px] sm:pl-[90px]"
: "py-2 sm:py-3",
isElectron ? "drag-region flex h-[52px] items-center" : "py-2 sm:py-3",
)}
>
<ChatHeader
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/home/ChatHomeEmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function ChatHomeEmptyState() {
)}

{isElectron && (
<div className="drag-region flex h-[52px] shrink-0 items-center justify-between gap-3 border-b border-border px-4 pl-[90px] sm:px-5 sm:pl-[90px]">
<div className="drag-region flex h-[52px] shrink-0 items-center justify-between gap-3 border-b border-border px-4 sm:px-5">
<div className="flex min-w-0 items-center gap-2">
<SidebarTrigger className="size-7 shrink-0" />
<span className="truncate text-xs font-medium tracking-[0.14em] text-muted-foreground/70 uppercase">
Expand Down
38 changes: 37 additions & 1 deletion apps/web/src/routes/_chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CommandPalette } from "../components/CommandPalette";
import { ScreenshotTool, ScreenshotButton } from "../components/ScreenshotTool";
import { WorktreeCleanupDialog } from "../components/WorktreeCleanupDialog";
import { useHandleNewThread } from "../hooks/useHandleNewThread";
import { readDesktopBridge } from "../lib/runtimeBridge";
import { isTerminalFocused } from "../lib/terminalFocus";
import { isMacPlatform } from "../lib/utils";
import { serverConfigQueryOptions } from "../lib/serverReactQuery";
Expand All @@ -19,7 +20,7 @@ import { useScreenshotStore } from "../screenshotStore";
import { useStore } from "../store";
import { resolveSidebarNewThreadEnvMode } from "~/components/Sidebar.logic";
import { useAppSettings } from "~/appSettings";
import { Sidebar, SidebarProvider, SidebarRail } from "~/components/ui/sidebar";
import { Sidebar, SidebarProvider, SidebarRail, useSidebar } from "~/components/ui/sidebar";
import { useAutoDeleteMergedThreads } from "~/hooks/useAutoDeleteMergedThreads";
import { useClientMode } from "~/hooks/useClientMode";
import { isMobileShell } from "../env";
Expand Down Expand Up @@ -215,6 +216,40 @@ function ChatRouteGlobalShortcuts() {
return null;
}

function ChatDesktopWindowButtonsSync() {
const { open } = useSidebar();

useEffect(() => {
if (typeof navigator === "undefined" || !isMacPlatform(navigator.platform)) {
return;
}

const bridge = readDesktopBridge();
if (!bridge || typeof bridge.setWindowButtonVisibility !== "function") {
return;
}

void bridge.setWindowButtonVisibility(open);
}, [open]);

useEffect(() => {
if (typeof navigator === "undefined" || !isMacPlatform(navigator.platform)) {
return;
}

const bridge = readDesktopBridge();
if (!bridge || typeof bridge.setWindowButtonVisibility !== "function") {
return;
}

return () => {
void bridge.setWindowButtonVisibility(true);
};
}, []);

return null;
}

function ChatRouteLayout() {
const navigate = useNavigate();
const { settings } = useAppSettings();
Expand Down Expand Up @@ -266,6 +301,7 @@ function ChatRouteLayout() {
/>
<div className="relative z-10 min-h-dvh">
<SidebarProvider defaultOpen={clientMode !== "mobile"}>
<ChatDesktopWindowButtonsSync />
<ChatRouteGlobalShortcuts />
<CommandPalette />
<WorktreeCleanupDialog />
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export interface DesktopBridge {
confirm: (message: string) => Promise<boolean>;
setTheme: (theme: DesktopTheme) => Promise<void>;
setSidebarOpacity: (opacity: number) => Promise<void>;
setWindowButtonVisibility: (visible: boolean) => Promise<void>;
showContextMenu: <T extends string>(
items: readonly ContextMenuItem<T>[],
position?: { x: number; y: number },
Expand Down
Loading