diff --git a/packages/app/e2e/browser/plugin-sidebar-items.spec.ts b/packages/app/e2e/browser/plugin-sidebar-items.spec.ts index e91b6a55d..3acf19a86 100644 --- a/packages/app/e2e/browser/plugin-sidebar-items.spec.ts +++ b/packages/app/e2e/browser/plugin-sidebar-items.spec.ts @@ -208,6 +208,35 @@ test.describe("Plugin sidebar items", () => { }); }); + test("a short desktop sidebar keeps workspaces usable while navigation scrolls", async ({ + page, + }) => { + await page.setViewportSize({ width: 1280, height: 480 }); + await gotoAppShell(page); + await expect(botRow(page, "status")).toBeAttached(); + const workspace = visibleTestId(page, `sidebar-workspace-row-${getServerId()}:${workspaceId}`); + await expect(workspace).toBeInViewport({ ratio: 1 }); + await expect(botRow(page, "status")).not.toBeInViewport(); + + await test.step("navigation stays within half the sidebar", async () => { + const nav = await boxOf(visibleTestId(page, "sidebar-nav-scroll")); + expect(nav.height).toBeLessThanOrEqual(480 / 2 + 1); + }); + + await test.step("scrolling navigation reaches its last row without moving workspaces", async () => { + const before = await boxOf(workspace); + await visibleTestId(page, "sidebar-global-new-workspace").hover(); + await page.mouse.wheel(0, 800); + await expect(botRow(page, "status")).toBeInViewport({ ratio: 1 }); + await expect(workspace).toBeInViewport({ ratio: 1 }); + expect((await boxOf(workspace)).y).toBe(before.y); + await qaScreenshot(page, "desktop-short-sidebar-nav-scrolled"); + await botRow(page, "status").click(); + await expect(page.getByText("Bot status details", { exact: true })).toBeVisible(); + await page.getByRole("button", { name: "Close bot status", exact: true }).click(); + }); + }); + test("a restored plugin screen waits for its catalog before rendering", async ({ page }) => { await page.setViewportSize(WIDE); await gotoWorkspace(page, workspaceId); diff --git a/packages/app/e2e/browser/sidebar-nav-settings.spec.ts b/packages/app/e2e/browser/sidebar-nav-settings.spec.ts index 618d44729..005d64c34 100644 --- a/packages/app/e2e/browser/sidebar-nav-settings.spec.ts +++ b/packages/app/e2e/browser/sidebar-nav-settings.spec.ts @@ -110,6 +110,7 @@ test.describe("Sidebar items in Appearance settings", () => { await test.step("the sidebar starts in the default order", async () => { await expectSidebarOrder(page, ["new-workspace", "history", "search", "schedules"]); + await expect(page.locator('[data-testid="sidebar-nav-separator"]:visible')).toHaveCount(1); }); await test.step("the Sidebar section lists every item in the same order", async () => { @@ -195,6 +196,9 @@ test.describe("Sidebar items in Appearance settings", () => { await expectSidebarItemHidden(page, "history"); await expectSidebarItemHidden(page, "search"); await expectSidebarItemHidden(page, "schedules"); + // Nothing is left above the Workspaces section: no drag strip, no empty divider. + await expect(page.locator('[data-testid="sidebar-nav-drag-strip"]:visible')).toHaveCount(0); + await expect(page.locator('[data-testid="sidebar-nav-separator"]:visible')).toHaveCount(0); }); }); diff --git a/packages/app/src/components/desktop/titlebar-drag-region.tsx b/packages/app/src/components/desktop/titlebar-drag-region.tsx index da115c734..e39e211bf 100644 --- a/packages/app/src/components/desktop/titlebar-drag-region.tsx +++ b/packages/app/src/components/desktop/titlebar-drag-region.tsx @@ -17,6 +17,13 @@ import { isNative } from "@/constants/platform"; * On macOS, Electron handles edge resize natively. */ +/** + * Marks a scroll viewport as window content: it and its descendants emit no window + * regions, because Electron does not clip app-region rects to scroll viewports. + * See the `[data-window-content]` rule in public/index.html. + */ +export const WINDOW_CONTENT_DATASET = { "window-content": "" }; + export const titlebarDragSurfaceStyle: React.CSSProperties = { cursor: "default", // @ts-expect-error — WebkitAppRegion is not in CSSProperties diff --git a/packages/app/src/components/left-sidebar.tsx b/packages/app/src/components/left-sidebar.tsx index 38b01fd33..55874b0fb 100644 --- a/packages/app/src/components/left-sidebar.tsx +++ b/packages/app/src/components/left-sidebar.tsx @@ -9,7 +9,16 @@ import { type LucideIcon, } from "lucide-react-native"; import { useTranslation } from "react-i18next"; -import { memo, useCallback, useEffect, useMemo, useRef, useState, type RefObject } from "react"; +import { + memo, + useCallback, + useEffect, + useMemo, + useRef, + useState, + type ReactNode, + type RefObject, +} from "react"; import { Pressable, ScrollView, @@ -19,12 +28,19 @@ import { View, type LayoutChangeEvent, } from "react-native"; -import { Gesture, ScrollView as GHScrollView } from "react-native-gesture-handler"; +import { + Gesture, + type GestureType, + ScrollView as GHScrollView, +} from "react-native-gesture-handler"; import Animated, { runOnJS, useAnimatedStyle, useSharedValue } from "react-native-reanimated"; import { scheduleOnRN } from "react-native-worklets"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { StyleSheet, useUnistyles } from "react-native-unistyles"; -import { TitlebarDragRegion } from "@/components/desktop/titlebar-drag-region"; +import { + TitlebarDragRegion, + WINDOW_CONTENT_DATASET, +} from "@/components/desktop/titlebar-drag-region"; import { SidebarCloseButton } from "@/components/headers/sidebar-close-button"; import { resolveDesktopSidebarInsetLeft, @@ -39,7 +55,7 @@ import { HostPicker } from "@/components/hosts/host-picker"; import { SidebarDisplayPreferencesMenu } from "@/components/sidebar/display-preferences/menu"; import { SidebarSeparator } from "@/components/sidebar/sidebar-separator"; import { SidebarToastRegion } from "@/components/sidebar/sidebar-toast-region"; -import { SidebarNavRows } from "@/components/sidebar/sidebar-nav-rows"; +import { SidebarNavRows, useVisibleSidebarNavItems } from "@/components/sidebar/sidebar-nav-rows"; import { SidebarFooterIconHighlight } from "@/components/sidebar/sidebar-footer-icon-highlight"; import { SidebarHelpMenu } from "@/components/sidebar/sidebar-help-menu"; import { SidebarFooterOverflowMenu } from "@/components/sidebar/sidebar-footer-overflow-menu"; @@ -622,29 +638,7 @@ function MobileSidebar({ > - {platformIsNative ? ( - - {navRows} - - ) : ( - - {navRows} - - )} - + {navRows} @@ -689,6 +683,47 @@ function MobileSidebar({ ); } +interface SidebarNavScrollProps { + closeGestureRef: RefObject; + /** Web only: the viewport emits no window regions (see WINDOW_CONTENT_DATASET). */ + windowContent?: boolean; + children: ReactNode; +} + +// The capped, scrolling nav block shared by the mobile and desktop sidebars, with the +// divider below it. The divider is a sibling because Unistyles does not patch the +// gesture-handler ScrollView. +function SidebarNavScroll({ closeGestureRef, windowContent, children }: SidebarNavScrollProps) { + return ( + <> + {platformIsNative ? ( + + {children} + + ) : ( + + {children} + + )} + + + ); +} + function DesktopSidebar({ theme, workspaceGroups, @@ -809,12 +844,14 @@ function DesktopSidebar({ ], [insetsTop, insets.bottom, insets.left, overlay, divisionLayout], ); - // Below the window controls' row, or in the top band's place, the first row starts flush. const inTopBand = useTopBand() !== null; - const sidebarHeaderGroupStyle = useMemo( - () => [styles.sidebarHeaderGroup, (ownsTopLeft || inTopBand) && styles.sidebarHeaderGroupFlush], - [ownsTopLeft, inTopBand], - ); + // Windows and Linux draw their window controls top-right, so the sidebar has no chrome + // row there. The strip above the scrolling rows is then its window drag surface. + const showsChromeRow = ownsTopLeft || Boolean(DEV_BUILD_LABEL); + // With every top item hidden the sidebar starts at the Workspaces section, as before the + // nav scroller existed: no strip above it and no divider below it. + const hasNavRows = useVisibleSidebarNavItems().length > 0; + const showsDragStrip = hasNavRows && !showsChromeRow && !inTopBand; return ( - {ownsTopLeft || DEV_BUILD_LABEL ? ( + {showsChromeRow ? ( {DEV_BUILD_LABEL ? ( @@ -842,11 +879,21 @@ function DesktopSidebar({ ) : null} - ) : ( - - )} - + ) : null} + {showsDragStrip ? ( + + + + ) : null} + {/* The drag overlay stays above this viewport: Electron does not clip + app-region rects to scroll viewports, so a scrolled-out row would + still claim its no-drag rect. */} + {hasNavRows ? ( + + + + ) : null} @@ -935,19 +982,18 @@ const staticStyles = RNStyleSheet.create({ }); const styles = StyleSheet.create((theme) => ({ + // The rows start flush: the chrome row, drag strip, or top band above them gives the inset. sidebarHeaderGroup: { - paddingTop: theme.spacing[2], gap: 2, paddingBottom: theme.spacing[1.5], - borderBottomWidth: 1, - borderBottomColor: theme.colors.border, }, - sidebarHeaderGroupFlush: { - paddingTop: 0, + desktopDragStrip: { + position: "relative", + height: theme.spacing[2], }, // The nav block caps at half the sidebar; a long item list scrolls inside the // cap instead of crowding the workspace list off a short screen. - mobileNavScroll: { + navScroll: { flexGrow: 0, flexShrink: 1, maxHeight: "50%", diff --git a/packages/app/src/components/sidebar/sidebar-nav-rows.tsx b/packages/app/src/components/sidebar/sidebar-nav-rows.tsx index 0f7e8c24c..88693752d 100644 --- a/packages/app/src/components/sidebar/sidebar-nav-rows.tsx +++ b/packages/app/src/components/sidebar/sidebar-nav-rows.tsx @@ -35,14 +35,19 @@ interface SidebarNavRowsProps extends SidebarNavRowProps { firstRowTrailing?: ReactNode; } +/** The top-level items the user keeps visible, in display order. */ +export function useVisibleSidebarNavItems() { + const { items } = useSidebarNavItems("header"); + return useMemo(() => items.filter((item) => item.visible), [items]); +} + /** * Top-level sidebar navigation, ordered and filtered by the user's * `sidebarNavItems` preference. Renders nothing — not even the bordered group * wrapper — when every item is hidden and there is no `firstRowTrailing`. */ export function SidebarNavRows({ style, onBeforeNavigate, firstRowTrailing }: SidebarNavRowsProps) { - const { items } = useSidebarNavItems("header"); - const visibleItems = useMemo(() => items.filter((item) => item.visible), [items]); + const visibleItems = useVisibleSidebarNavItems(); const groupRef = useRef(null); if (visibleItems.length === 0 && !firstRowTrailing) return null; diff --git a/packages/app/src/screens/open-project-screen.tsx b/packages/app/src/screens/open-project-screen.tsx index 4fcbb4d2f..0f55a9eeb 100644 --- a/packages/app/src/screens/open-project-screen.tsx +++ b/packages/app/src/screens/open-project-screen.tsx @@ -21,8 +21,7 @@ import { import { useLocalDaemonServerId } from "@/hooks/use-is-local-daemon"; import { PairDeviceModal } from "@/desktop/components/pair-device-modal"; import { buildSettingsHostSectionRoute } from "@/utils/host-routes"; - -const WINDOW_CONTENT_DATASET = { "window-content": "" }; +import { WINDOW_CONTENT_DATASET } from "@/components/desktop/titlebar-drag-region"; export function OpenProjectScreen() { const { t } = useTranslation(); diff --git a/packages/desktop/e2e/sidebar-nav-drag-region.spec.ts b/packages/desktop/e2e/sidebar-nav-drag-region.spec.ts new file mode 100644 index 000000000..18e1e7c91 --- /dev/null +++ b/packages/desktop/e2e/sidebar-nav-drag-region.spec.ts @@ -0,0 +1,64 @@ +import type { Page } from "@playwright/test"; +import { test, expect } from "../../app/e2e/support/fixtures"; +import { gotoAppShell } from "../../app/e2e/support/helpers/app"; + +// Windows and Linux draw their window controls top-right, so the desktop sidebar has no +// chrome row of its own. Its window-drag surface is the strip above the navigation rows. +const CUSTOM_CHROME_HOSTS = [ + { platform: "linux", windowChromeMode: "custom-linux" }, + { platform: "win32", windowChromeMode: "custom-windows" }, +] as const; + +async function installDesktopHost( + page: Page, + host: (typeof CUSTOM_CHROME_HOSTS)[number], +): Promise { + await page.addInitScript((desktopHost) => { + window.paseoDesktop = { + ...desktopHost, + events: { on: () => () => {} }, + invoke: async (command: string) => { + if (command === "get_desktop_settings") { + return { + releaseChannel: "stable", + daemon: { manageBuiltInDaemon: true, keepRunningAfterQuit: true }, + }; + } + return null; + }, + }; + }, host); +} + +async function sidebarDragGeometry(page: Page) { + const navScroll = page.locator('[data-testid="sidebar-nav-scroll"]:visible').first(); + await expect(navScroll).toBeVisible(); + return navScroll.evaluate((node) => { + const nav = node.getBoundingClientRect(); + const dragRegions = []; + for (const element of document.querySelectorAll("*")) { + if (getComputedStyle(element).getPropertyValue("-webkit-app-region") !== "drag") continue; + const rect = element.getBoundingClientRect(); + const overSidebar = rect.left < nav.right && rect.right > nav.left; + if (overSidebar && rect.height > 0) dragRegions.push({ top: rect.top, bottom: rect.bottom }); + } + return { navTop: nav.top, navBottom: nav.bottom, dragRegions }; + }); +} + +for (const host of CUSTOM_CHROME_HOSTS) { + test.describe(`Desktop sidebar on ${host.platform}`, () => { + test.use({ viewport: { width: 1280, height: 480 } }); + + test("keeps a window drag strip above the scrolling navigation", async ({ page }) => { + await installDesktopHost(page, host); + await gotoAppShell(page); + + const geometry = await sidebarDragGeometry(page); + expect(geometry.dragRegions).not.toEqual([]); + for (const region of geometry.dragRegions) { + expect(region.bottom).toBeLessThanOrEqual(geometry.navTop + 1); + } + }); + }); +}