TypeScript
fix(desktop): allow half-screen tiling on scaled displays (#19232)
Tanner Polley9497ab5db3ee
diff --git a/apps/desktop/src/settings/DesktopAppSettings.test.ts b/apps/desktop/src/settings/DesktopAppSettings.test.tsindex a98aa96079e..7313b9b859e 100644--- a/apps/desktop/src/settings/DesktopAppSettings.test.ts+++ b/apps/desktop/src/settings/DesktopAppSettings.test.ts@@ -283,7 +283,7 @@ describe("DesktopSettings", () => {Effect.gen(function* () {const settings = yield* DesktopAppSettings.DesktopAppSettings;yield* writeSettingsPatch({- mainWindowBounds: { x: 10.5, y: 20, width: 839, height: 620 },+ mainWindowBounds: { x: 10, y: 20, width: 599, height: 620 },mainWindowMaximized: true,serverExposureMode: "network-accessible",});@@ -342,17 +342,24 @@ describe("DesktopSettings", () => {const fileSystem = yield* FileSystem.FileSystem;const settings = yield* DesktopAppSettings.DesktopAppSettings;- yield* settings.setMainWindowBounds({ x: -1200, y: 40, width: 1440, height: 960 }, true);+ yield* settings.setMainWindowBounds({ x: -1200, y: 40, width: 600, height: 620 }, true);yield* settings.setServerExposureMode("network-accessible");const persisted = yield* decodeDesktopSettingsPatch(yield* fileSystem.readFileString(environment.desktopSettingsPath),);assert.deepEqual(persisted, {- mainWindowBounds: { x: -1200, y: 40, width: 1440, height: 960 },+ mainWindowBounds: { x: -1200, y: 40, width: 600, height: 620 },mainWindowMaximized: true,serverExposureMode: "network-accessible",} satisfies typeof DesktopSettingsPatch.Type);++ const restored = yield* Effect.gen(function* () {+ const freshSettings = yield* DesktopAppSettings.DesktopAppSettings;+ return yield* freshSettings.load;+ }).pipe(Effect.provide(DesktopAppSettings.layer));+ assert.deepEqual(restored.mainWindowBounds, persisted.mainWindowBounds);+ assert.isTrue(restored.mainWindowMaximized);}),),);diff --git a/apps/desktop/src/settings/DesktopAppSettings.ts b/apps/desktop/src/settings/DesktopAppSettings.tsindex 1c131681295..a26892d6984 100644--- a/apps/desktop/src/settings/DesktopAppSettings.ts+++ b/apps/desktop/src/settings/DesktopAppSettings.ts@@ -48,8 +48,8 @@ export interface DesktopSettingsChange {}const DEFAULT_TAILSCALE_SERVE_PORT = 443;-const MIN_MAIN_WINDOW_SIZE = {- width: 840,+export const MIN_MAIN_WINDOW_SIZE = {+ width: 600,height: 620,} as const;export const DesktopWindowBoundsSchema = Schema.Struct({diff --git a/apps/desktop/src/window/DesktopWindow.test.ts b/apps/desktop/src/window/DesktopWindow.test.tsindex 56206a22796..827a48997fb 100644--- a/apps/desktop/src/window/DesktopWindow.test.ts+++ b/apps/desktop/src/window/DesktopWindow.test.ts@@ -660,6 +660,8 @@ describe("DesktopWindow", () => {assert.equal(yield* Ref.get(createCount), 1);assert.equal(createdWindowOptions[0]?.width, 1100);assert.equal(createdWindowOptions[0]?.height, 780);+ assert.equal(createdWindowOptions[0]?.minWidth, 600);+ assert.equal(createdWindowOptions[0]?.minHeight, 620);assert.isUndefined(createdWindowOptions[0]?.x);assert.isUndefined(createdWindowOptions[0]?.y);assert.isTrue(createdWindowOptions[0]?.disableAutoHideCursor);@@ -918,7 +920,7 @@ describe("DesktopWindow", () => {createdWindowOptions,desktopSettings: {...DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,- mainWindowBounds: { x: 120, y: 80, width: 1320, height: 880 },+ mainWindowBounds: { x: 120, y: 80, width: 768, height: 780 },},});@@ -926,8 +928,8 @@ describe("DesktopWindow", () => {const desktopWindow = yield* DesktopWindow.DesktopWindow;yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));- assert.equal(createdWindowOptions[0]?.width, 1320);- assert.equal(createdWindowOptions[0]?.height, 880);+ assert.equal(createdWindowOptions[0]?.width, 768);+ assert.equal(createdWindowOptions[0]?.height, 780);assert.equal(createdWindowOptions[0]?.x, 120);assert.equal(createdWindowOptions[0]?.y, 80);}).pipe(Effect.provide(layer));@@ -1152,14 +1154,14 @@ describe("DesktopWindow", () => {move();yield* TestClock.adjust(250);- fakeWindow.getBounds.mockReturnValue({ x: 160, y: 100, width: 1360, height: 900 });+ fakeWindow.getBounds.mockReturnValue({ x: 160, y: 100, width: 664, height: 780 });resize();yield* TestClock.adjust(499);assert.deepEqual(mainWindowBoundsUpdates, []);yield* TestClock.adjust(1);yield* Effect.promise(() => Promise.resolve());- assert.deepEqual(mainWindowBoundsUpdates, [{ x: 160, y: 100, width: 1360, height: 900 }]);+ assert.deepEqual(mainWindowBoundsUpdates, [{ x: 160, y: 100, width: 664, height: 780 }]);}).pipe(Effect.provide(layer));}),);@@ -1241,7 +1243,7 @@ describe("DesktopWindow", () => {it.effect("does not persist bounds that fail the domain schema", () =>Effect.gen(function* () {const fakeWindow = makeFakeBrowserWindow();- fakeWindow.getBounds.mockReturnValue({ x: 100.4, y: 80.2, width: 839.4, height: 619.4 });+ fakeWindow.getBounds.mockReturnValue({ x: 100, y: 80, width: 599, height: 620 });const createCount = yield* Ref.make(0);const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());const mainWindowBoundsUpdates: DesktopAppSettings.DesktopWindowBounds[] = [];diff --git a/apps/desktop/src/window/DesktopWindow.ts b/apps/desktop/src/window/DesktopWindow.tsindex 5d14fdfdc53..f99eeffd62c 100644--- a/apps/desktop/src/window/DesktopWindow.ts+++ b/apps/desktop/src/window/DesktopWindow.ts@@ -383,8 +383,8 @@ export const make = Effect.gen(function* () {if (yield* Ref.get(desktopState.quitting)) return Option.none();const window = yield* electronWindow.create({...initialBounds,- minWidth: 840,- minHeight: 620,+ minWidth: DesktopAppSettings.MIN_MAIN_WINDOW_SIZE.width,+ minHeight: DesktopAppSettings.MIN_MAIN_WINDOW_SIZE.height,show: false,autoHideMenuBar: true,...(environment.platform === "darwin" ? { disableAutoHideCursor: true } : {}),diff --git a/apps/web/src/components/AppSidebarLayout.tsx b/apps/web/src/components/AppSidebarLayout.tsxindex 89d52c87b28..c991a900351 100644--- a/apps/web/src/components/AppSidebarLayout.tsx+++ b/apps/web/src/components/AppSidebarLayout.tsx@@ -321,6 +321,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {className="h-dvh! min-h-0!"data-panel-animations={routePanelAnimationsActive ? "true" : "false"}defaultOpen+ mobileBreakpoint={sidebarMinimumWidth + THREAD_MAIN_CONTENT_MIN_WIDTH}style={sidebarProviderStyle}><SidebarBrandWidthProbe onWidthChange={setBrandWidth} />diff --git a/apps/web/src/components/LegacySidebar.tsx b/apps/web/src/components/LegacySidebar.tsxindex 9076b9c127c..70c7d7b0c1f 100644--- a/apps/web/src/components/LegacySidebar.tsx+++ b/apps/web/src/components/LegacySidebar.tsx@@ -204,7 +204,6 @@ import {import { sortThreads } from "../lib/threadSort";import { SidebarChromeFooter, SidebarChromeHeader } from "./sidebar/SidebarChrome";import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";-import { useIsMobile } from "~/hooks/useMediaQuery";import { CommandDialogTrigger } from "./ui/command";import { useClientSettings, updateClientSettings } from "~/hooks/useSettings";import { primaryServerKeybindingsAtom } from "../state/server";@@ -420,7 +419,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowPenvironmentId: thread.environmentId,threadId: thread.id,});- const isMobile = useIsMobile();+ const { isMobile } = useSidebar();const discoveredPorts = useThreadDiscoveredPorts({environmentId: thread.environmentId,threadId: thread.id,diff --git a/apps/web/src/components/sidebar/SidebarChrome.tsx b/apps/web/src/components/sidebar/SidebarChrome.tsxindex e7a61f6e992..c04edb1799f 100644--- a/apps/web/src/components/sidebar/SidebarChrome.tsx+++ b/apps/web/src/components/sidebar/SidebarChrome.tsx@@ -36,6 +36,7 @@ export const SidebarChromeHeader = memo(function SidebarChromeHeader({}: {isElectron: boolean;}) {+ const { isMobile } = useSidebar();const stageLabel = useEnvironmentStageLabel();const environmentIdentificationMode = useEnvironmentIdentificationMode();const backdropVariant = resolveSidebarStageBackdropVariant(@@ -55,15 +56,17 @@ export const SidebarChromeHeader = memo(function SidebarChromeHeader({)}>{backdropVariant ? <SidebarStageBackdrop variant={backdropVariant} /> : null}- <div className="relative top-[calc(var(--workspace-controls-top)-env(safe-area-inset-top))] z-10 ml-[calc(var(--workspace-controls-left)+1px-env(safe-area-inset-left))] flex shrink-0 items-center md:hidden">- <SidebarTrigger- variant={backdropVariant ? "media-navigation" : "ghost"}- className="relative top-auto translate-y-0"- aria-label="Toggle main sidebar"- />- </div>+ {isMobile ? (+ <div className="relative top-[calc(var(--workspace-controls-top)-env(safe-area-inset-top))] z-10 ml-[calc(var(--workspace-controls-left)+1px-env(safe-area-inset-left))] flex shrink-0 items-center">+ <SidebarTrigger+ variant={backdropVariant ? "media-navigation" : "ghost"}+ className="relative top-auto translate-y-0"+ aria-label="Toggle main sidebar"+ />+ </div>+ ) : null}<div className="relative z-10 flex h-8 min-w-0 flex-1 flex-wrap content-start items-center gap-x-2 overflow-hidden py-0.5">- <SidebarBrand onBackdrop={backdropVariant !== null} />+ {!isMobile ? <SidebarBrand onBackdrop={backdropVariant !== null} /> : null}{pillLabel ? (<div className="ml-1 flex h-7 items-center"><Badge data-environment-identification="pill" size="sm" variant="secondary">@@ -105,7 +108,7 @@ function SidebarBrand({ onBackdrop }: { onBackdrop: boolean }) {<Linkaria-label="Go to threads"className={cn(- "relative z-10 ml-[var(--workspace-titlebar-content-left)] hidden h-7 w-fit min-w-0 shrink-0 items-center overflow-hidden rounded-md outline-hidden ring-ring focus-visible:ring-2 focus-visible:ring-inset md:flex",+ "relative z-10 ml-[var(--workspace-titlebar-content-left)] flex h-7 w-fit min-w-0 shrink-0 items-center overflow-hidden rounded-md outline-hidden ring-ring focus-visible:ring-2 focus-visible:ring-inset",onBackdrop ? "text-white" : "text-foreground",)}to="/"diff --git a/apps/web/src/components/ui/sidebar.tsx b/apps/web/src/components/ui/sidebar.tsxindex 570e8299694..3e44922a7b9 100644--- a/apps/web/src/components/ui/sidebar.tsx+++ b/apps/web/src/components/ui/sidebar.tsx@@ -17,7 +17,7 @@ import {} from "~/components/ui/sheet";import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";import { useResizeDrag } from "~/hooks/useResizeDrag";-import { useIsMobile } from "~/hooks/useMediaQuery";+import { useMediaQuery } from "~/hooks/useMediaQuery";import { getLocalStorageItem, setLocalStorageItem } from "~/hooks/useLocalStorage";import { resolveSidebarState, type ResponsiveSidebarState } from "./sidebarState";import * as Schema from "effect/Schema";@@ -96,6 +96,7 @@ function useSidebarVisibility() {function SidebarProvider({defaultOpen = true,+ mobileBreakpoint,open: openProp,onOpenChange: setOpenProp,className,@@ -104,11 +105,17 @@ function SidebarProvider({...props}: React.ComponentProps<"div"> & {defaultOpen?: boolean;+ mobileBreakpoint?: number;open?: boolean;onOpenChange?: (open: boolean) => void;}) {- const isMobile = useIsMobile();+ const isMobile = useMediaQuery(+ mobileBreakpoint === undefined ? "max-md" : { max: mobileBreakpoint },+ );const [openMobile, setOpenMobile] = React.useState(false);+ if (!isMobile && openMobile) {+ setOpenMobile(false);+ }const [mobileSheetMounted, setMobileSheetMounted] = React.useState(false);const setMobileSheetElement = (element: HTMLDivElement | null) => {setMobileSheetMounted(element !== null);@@ -158,6 +165,7 @@ function SidebarProvider({SIDEBAR_TITLEBAR_CONTROL_SIZE,className,)}+ data-sidebar-mobile={isMobile}data-sidebar-state={state}data-slot="sidebar-wrapper"style={@@ -298,7 +306,7 @@ function Sidebar({<SidebarInstanceContext value={instanceContextValue}><divref={desktopSidebarRef}- className="group peer hidden text-sidebar-foreground md:block"+ className="group peer text-sidebar-foreground"data-collapsible={state === "collapsed" ? collapsible : ""}data-side={side}data-slot="sidebar"@@ -319,7 +327,7 @@ function Sidebar({/><divclassName={cn(- "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) md:flex",+ "fixed inset-y-0 z-10 flex h-svh w-(--sidebar-width)","[[data-panel-animations=true]_&]:transition-[left,right,width] [[data-panel-animations=true]_&]:[transition-duration:var(--panel-animation-duration)] [[data-panel-animations=true]_&]:ease-out",side === "left"? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"diff --git a/apps/web/src/hooks/useMediaQuery.ts b/apps/web/src/hooks/useMediaQuery.tsindex ec6ee4fa511..f3df1b3a4b1 100644--- a/apps/web/src/hooks/useMediaQuery.ts+++ b/apps/web/src/hooks/useMediaQuery.ts@@ -77,7 +77,3 @@ export function useMediaQuery(query: BreakpointQuery | MediaQueryInput | (stringreturn useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);}--export function useIsMobile(): boolean {- return useMediaQuery("max-md");-}diff --git a/apps/web/src/workspaceTitlebar.ts b/apps/web/src/workspaceTitlebar.tsindex 729fdfa00dc..8813f9b8160 100644--- a/apps/web/src/workspaceTitlebar.ts+++ b/apps/web/src/workspaceTitlebar.ts@@ -1,2 +1,2 @@export const COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS =- "[[data-sidebar-state=collapsed]_&]:pl-[var(--workspace-titlebar-content-left)] max-md:[[data-sidebar-state=expanded]_&]:pl-[var(--workspace-titlebar-content-left)]";+ "[[data-sidebar-state=collapsed]_&]:pl-[var(--workspace-titlebar-content-left)] [[data-sidebar-mobile=true][data-sidebar-state=expanded]_&]:pl-[var(--workspace-titlebar-content-left)]";