Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): reserve chrome actions space in maximized sidebar (#323)

JustinBaof002ac3929e0
diff --git a/apps/desktop/src/renderer/components/layout/MainLayout.tsx b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
index b2b74f5ad5..4e4baa6eef 100644
--- a/apps/desktop/src/renderer/components/layout/MainLayout.tsx
+++ b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
@@ -1211,6 +1211,7 @@ export function MainLayout() {
onCloseSidebar={isMac ? undefined : handleToggleRightSidebar}
onMaximize={handleMaximizeRightSidebar}
isMaximized={isRightSidebarMaximized}
+ reserveLeftChromeActions={isRightSidebarMaximized && isSidebarCollapsed}
sessionId={rightSidebarSessionId}
workdir={rightSidebarWorkdirInfo.workdir}
remoteHostId={rightSidebarWorkdirInfo.remoteHostId}
diff --git a/apps/desktop/src/renderer/components/layout/RightSidebar.tsx b/apps/desktop/src/renderer/components/layout/RightSidebar.tsx
index e00f955da4..5f712a1fcc 100644
--- a/apps/desktop/src/renderer/components/layout/RightSidebar.tsx
+++ b/apps/desktop/src/renderer/components/layout/RightSidebar.tsx
@@ -66,6 +66,8 @@ interface RightSidebarProps {
/** Maximize 态(Phase 6):RSB 撑满整个非左栏区,主区 hidden。本组件用来隐藏
* resize handle(maximize 不允许拖宽)+ 把 TabBar maximize 按钮图标切到"还原"。 */
isMaximized?: boolean;
+ /** 左侧栏完全收起且 RSB maximize 时,为顶栏左上角浮动 ChromeActions 让位。 */
+ reserveLeftChromeActions?: boolean;
/** 「在新窗口中打开侧边栏」:开偏好 + 弹出子窗口。Win 端 TabBar 内渲染按钮
* (Mac 走 MainLayout 浮层,不经此 prop)。 */
onDetach?: () => void;
@@ -84,6 +86,7 @@ export const RightSidebar = forwardRef<RightSidebarHandle, RightSidebarProps>(fu
onCloseSidebar,
onMaximize,
isMaximized,
+ reserveLeftChromeActions = false,
sessionId,
workdir,
remoteHostId,
@@ -254,6 +257,7 @@ export const RightSidebar = forwardRef<RightSidebarHandle, RightSidebarProps>(fu
onCloseSidebar={onCloseSidebar}
onMaximize={onMaximize}
isMaximized={isMaximized}
+ reserveLeftChromeActions={reserveLeftChromeActions}
onDetach={onDetach}
// B3:主窗口内嵌形态 Tab 条空白处 = 拖面板手势面(窗口拖动走左栏顶行)。
chromeWindowDrag={false}
diff --git a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
index 644d8fd876..0c58a357f9 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
@@ -24,8 +24,10 @@ import { useTranslation } from 'react-i18next';
import { createLogger } from '@/lib/logger';
import { useAppShortcut } from '@/hooks/useAppShortcut';
+import { useMacFullscreen } from '@/hooks/useMacFullscreen';
import { RightSidebarDetach } from '@/components/layout/RightSidebarDetach';
import { RightSidebarMaximize } from '@/components/layout/RightSidebarMaximize';
+import { CHROME_ACTIONS_GEOMETRY } from '@/components/layout/chromeActionsGeometry';
import { TabBar, TabStrip } from './TabBar';
import { EmptyState } from './EmptyState';
import {
@@ -92,6 +94,12 @@ interface RightSidebarShellProps {
onMaximize?: () => void;
/** maximize 态 — 用来让 TabBar 把 maximize 按钮换图标(Maximize2 ↔ Minimize2)。 */
isMaximized?: boolean;
+ /**
+ * 主窗口左栏完全收起且当前面板 maximize 时,右栏 unified topbar 需要为
+ * MainLayout 的浮动 ChromeActions 预留左侧 no-drag 占位;普通右栏/rail/独立
+ * 子窗口不应消费这段空间。
+ */
+ reserveLeftChromeActions?: boolean;
/** 「在新窗口中打开侧边栏」;仅 Win 端 TabBar 内渲染按钮(Mac 走 MainLayout 浮层)。 */
onDetach?: () => void;
/** TabBar 横带是否作为窗口拖拽区(见 TabBar 同名 prop):主窗口内嵌形态传
@@ -124,7 +132,19 @@ export function RightSidebarShell({
chromeWindowDrag = true,
panelSide = 'right',
onAllTabsClosed,
+ reserveLeftChromeActions = false,
}: RightSidebarShellProps) {
+ const { isFullscreen } = useMacFullscreen();
+ const chromeActionsLeft =
+ isMac && !isFullscreen
+ ? CHROME_ACTIONS_GEOMETRY.macTrafficLightLeft
+ : CHROME_ACTIONS_GEOMETRY.defaultLeft;
+ // unifiedTopbar 本身有 px-2(8px) 左内边距。加上 chromeActionsLeft 后,
+ // spacer 的布局起点正好落在 ChromeActions 簇之前,并在簇后保留 8px 呼吸间距。
+ const leftChromeActionsSpacerWidth =
+ unifiedTopbar && reserveLeftChromeActions
+ ? chromeActionsLeft + CHROME_ACTIONS_GEOMETRY.clusterWidth
+ : 0;
const { t } = useTranslation();
// RSB browser bridge (Phase 2):在 Shell 整个生命周期内只 init 一次。bridge 内部
@@ -363,6 +383,19 @@ export function RightSidebarShell({
className="relative flex h-[46px] shrink-0 flex-none items-center border-b border-[var(--border-default)] bg-[var(--panel-bg)] px-2"
style={{ WebkitAppRegion: 'drag' } as React.CSSProperties}
>
+ {leftChromeActionsSpacerWidth > 0 && (
+ <div
+ aria-hidden
+ data-testid="right-sidebar-left-chrome-actions-spacer"
+ className="h-full shrink-0"
+ style={
+ {
+ width: leftChromeActionsSpacerWidth,
+ WebkitAppRegion: 'no-drag',
+ } as React.CSSProperties
+ }
+ />
+ )}
{/* pillVariant="chip":pills 垂直居中的浮动 chip(完整圆角 + 四边框),
与「+」、右侧浮层按钮共享宿主栏水平中线(对齐 Codex)——贴底 flush
样式在 46px 高栏里会与居中控件错位。
diff --git a/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts b/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
index 285c9a3c12..d5a1c7b9c7 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
@@ -21,6 +21,7 @@ vi.mock('../plugins', () => ({}));
import { RightSidebarShell } from '../RightSidebarShell';
import { _resetRsbBrowserBridgeForTests } from '../lib/rsbBrowserBridge';
import { _resetStore, closeTab } from '../store';
+import { CHROME_ACTIONS_GEOMETRY } from '@/components/layout/chromeActionsGeometry';
interface RightSidebarTabsIpcStub {
list: ReturnType<typeof vi.fn>;
@@ -50,7 +51,7 @@ function makeRightSidebarTabsIpc(): RightSidebarTabsIpcStub {
};
}
-function installElectronApi(tabsIpc: RightSidebarTabsIpcStub): void {
+function installElectronApi(tabsIpc: RightSidebarTabsIpcStub, fullscreen = false): void {
(
window as unknown as {
electronAPI: {
@@ -69,6 +70,8 @@ function installElectronApi(tabsIpc: RightSidebarTabsIpcStub): void {
onRsbBrowserCommand: (
callback: (payload: { command: RsbBrowserCommand }) => void,
) => () => void;
+ getFullscreenState: () => Promise<boolean>;
+ onFullscreenChange: (callback: (fullscreen: boolean) => void) => () => void;
appShortcuts: {
getState: () => { platform: string; overrides: AppShortcutOverrides };
onChanged: ReturnType<typeof vi.fn>;
@@ -120,6 +123,8 @@ function installElectronApi(tabsIpc: RightSidebarTabsIpcStub): void {
rsbBrowserCommandListeners = rsbBrowserCommandListeners.filter((cb) => cb !== callback);
};
},
+ getFullscreenState: vi.fn(async () => fullscreen),
+ onFullscreenChange: vi.fn(() => () => undefined),
appShortcuts: {
getState: () => ({ platform: 'darwin', overrides: {} }),
onChanged: vi.fn(() => () => undefined),
@@ -329,6 +334,61 @@ describe('RightSidebarShell empty state', () => {
expect(screen.getByRole('button', { name: 'rightSidebar.tabs.addAria' })).toBeTruthy();
});
+ it('reserves the fullscreen ChromeActions area in the maximized unified topbar', async () => {
+ installElectronApi(tabsIpc, true);
+ const { rerender } = render(
+ createElement(RightSidebarShell, {
+ sessionId: 's1',
+ workdir: '/tmp/repo',
+ remoteHostId: null,
+ isMac: true,
+ unifiedTopbar: true,
+ reserveLeftChromeActions: true,
+ }),
+ );
+
+ await waitFor(() => {
+ const spacer = screen.getByTestId('right-sidebar-left-chrome-actions-spacer');
+ expect(spacer.style.width).toBe(
+ `${CHROME_ACTIONS_GEOMETRY.defaultLeft + CHROME_ACTIONS_GEOMETRY.clusterWidth}px`,
+ );
+ });
+ const spacer = screen.getByTestId('right-sidebar-left-chrome-actions-spacer');
+ expect(
+ (spacer.style as CSSStyleDeclaration & { WebkitAppRegion: string }).WebkitAppRegion,
+ ).toBe('no-drag');
+
+ rerender(
+ createElement(RightSidebarShell, {
+ sessionId: 's1',
+ workdir: '/tmp/repo',
+ remoteHostId: null,
+ isMac: true,
+ unifiedTopbar: true,
+ reserveLeftChromeActions: false,
+ }),
+ );
+ expect(screen.queryByTestId('right-sidebar-left-chrome-actions-spacer')).toBeNull();
+ });
+
+ it('keeps the traffic-light offset when reserving ChromeActions outside fullscreen', async () => {
+ render(
+ createElement(RightSidebarShell, {
+ sessionId: 's1',
+ workdir: '/tmp/repo',
+ remoteHostId: null,
+ isMac: true,
+ unifiedTopbar: true,
+ reserveLeftChromeActions: true,
+ }),
+ );
+
+ const spacer = await screen.findByTestId('right-sidebar-left-chrome-actions-spacer');
+ expect(spacer.style.width).toBe(
+ `${CHROME_ACTIONS_GEOMETRY.macTrafficLightLeft + CHROME_ACTIONS_GEOMETRY.clusterWidth}px`,
+ );
+ });
+
it('renders detach/maximize in the topbar when panel is docked left (mac M2), spacer when right or maximized', async () => {
// 贴左:窗口右上浮层只剩折叠 toggle(恒钉窗口右上角,2026-07-09 Lizi 口径),
// detach / maximize 是面板自属控件,必须由 Shell 顶栏右端自渲染,否则面板