From c8d6cc53c6298016c05b811ff4d6fd964cf0da11 Mon Sep 17 00:00:00 2001 From: Lukas Tomondy Date: Wed, 11 Nov 2026 09:35:16 +0100 Subject: [PATCH] feat(web): add a setting to skip floating previews on panel close Closing the right panel always moved its browser or device preview into the floating preview, even with Auto-show floating preview turned off, since that setting only covers previews an agent opens. Add "Float preview on panel close" below it, on by default so current behavior is unchanged. When off, closing the panel also drops a float hidden behind that tab so it cannot reappear. Co-Authored-By: Claude Opus 5.5 --- .../settings/DesktopClientSettings.test.ts | 1 + .../components/chat/useRightPanelActions.ts | 26 +++++----- .../preview/agentOpenedPreviews.test.ts | 48 +++++++++++++++++++ .../components/preview/agentOpenedPreviews.ts | 23 +++++++++ .../settings/IntegrationsSettings.tsx | 36 ++++++++++++++ .../settings/SettingsPanels.logic.ts | 5 ++ .../components/settings/SettingsPanels.tsx | 1 + .../src/components/settings/settingsSearch.ts | 6 +++ packages/contracts/src/settings.ts | 6 +++ 9 files changed, 140 insertions(+), 12 deletions(-) diff --git a/apps/desktop/src/settings/DesktopClientSettings.test.ts b/apps/desktop/src/settings/DesktopClientSettings.test.ts index 1ab9b3159e1f..726ed70f1bf6 100644 --- a/apps/desktop/src/settings/DesktopClientSettings.test.ts +++ b/apps/desktop/src/settings/DesktopClientSettings.test.ts @@ -28,6 +28,7 @@ const clientSettings: ClientSettings = { browserRecordingFrameRate: 60, browserLinkTarget: "app", browserAutoShowFloatingPreview: false, + browserFloatPreviewOnPanelClose: false, browserProfiles: [{ id: "work", name: "Work", kind: "persistent" }], browserDefaultProfileId: "work", confirmQuit: "double-click", diff --git a/apps/web/src/components/chat/useRightPanelActions.ts b/apps/web/src/components/chat/useRightPanelActions.ts index 25ec5c22c2e1..cc43b12d3309 100644 --- a/apps/web/src/components/chat/useRightPanelActions.ts +++ b/apps/web/src/components/chat/useRightPanelActions.ts @@ -26,8 +26,9 @@ import { isBrowserSettingsReadError } from "../../browser/openFileInPreview"; import { addBrowserSurface } from "../preview/addBrowserSurface"; import { focusActivePanelTerminal, focusTerminal } from "../../lib/terminalFocus"; import { subscribePreviewAction } from "../preview/previewActionBus"; -import { floatDeviceSurface } from "../preview/agentOpenedPreviews"; -import { browserMiniPlayerSource, usePreviewMiniPlayerStore } from "../../previewMiniPlayerStore"; +import { getClientSettings } from "../../hooks/useSettings"; +import { settlePanelPreviewOnClose } from "../preview/agentOpenedPreviews"; +import { browserMiniPlayerSource } from "../../previewMiniPlayerStore"; import type { threadPullRequestPanelTarget } from "../pullRequest/pullRequestDetail.logic"; import type { useDeviceState } from "../../state/device"; import { stackedThreadToast, toastManager } from "../ui/toast"; @@ -168,16 +169,17 @@ export function useRightPanelActions(input: RightPanelActionsInput) { const openFileSurfaceStable = useStableCallback(openFileSurface); const closePreviewPanel = () => { if (activeThreadRef) { - if (activeRightPanelSurface?.kind === "preview" && activeRightPanelSurface.resourceId) { - usePreviewMiniPlayerStore - .getState() - .open(activeThreadRef, browserMiniPlayerSource(activeRightPanelSurface.resourceId)); - } else if (activeRightPanelSurface?.kind === "device" && activeRightPanelSurface.target) { - floatDeviceSurface( - activeThreadRef, - { kind: "device", ...activeRightPanelSurface.target }, - deviceStateLoaded ? deviceState : null, - ); + const source = + activeRightPanelSurface?.kind === "preview" && activeRightPanelSurface.resourceId + ? browserMiniPlayerSource(activeRightPanelSurface.resourceId) + : activeRightPanelSurface?.kind === "device" && activeRightPanelSurface.target + ? ({ kind: "device", ...activeRightPanelSurface.target } as const) + : null; + if (source) { + settlePanelPreviewOnClose(activeThreadRef, source, { + floatOnClose: getClientSettings().browserFloatPreviewOnPanelClose, + deviceState: deviceStateLoaded ? deviceState : null, + }); } useRightPanelStore.getState().setMaximized(activeThreadRef, false); useRightPanelStore.getState().close(activeThreadRef); diff --git a/apps/web/src/components/preview/agentOpenedPreviews.test.ts b/apps/web/src/components/preview/agentOpenedPreviews.test.ts index dee29a16cf52..414c44df9dd5 100644 --- a/apps/web/src/components/preview/agentOpenedPreviews.test.ts +++ b/apps/web/src/components/preview/agentOpenedPreviews.test.ts @@ -24,6 +24,7 @@ import { followPreviewSessions, resetDeviceSessionBaselinesForTests, revealServerTabs, + settlePanelPreviewOnClose, startAgentOpenedPreviews, } from "./agentOpenedPreviews"; @@ -195,6 +196,53 @@ describe("floatDeviceSurface", () => { }); }); +describe("settlePanelPreviewOnClose", () => { + const browser = browserMiniPlayerSource("tab_panel"); + const pixel = { + kind: "device", + hostId: "local", + deviceId: "pixel", + platform: "android", + name: "Pixel 8", + } as const; + const otherBrowser = browserMiniPlayerSource("tab_other"); + + it.each([ + { name: "floats a browser", source: browser, on: true, before: null, after: browser }, + { name: "floats a device", source: pixel, on: true, before: null, after: pixel }, + { name: "leaves nothing floating", source: browser, on: false, before: null, after: undefined }, + { + name: "closes a browser hidden behind the panel", + source: browser, + on: false, + before: browser, + after: undefined, + }, + { + name: "closes a device hidden behind the panel", + source: pixel, + on: false, + before: pixel, + after: undefined, + }, + { + name: "keeps a float of another tab", + source: browser, + on: false, + before: otherBrowser, + after: otherBrowser, + }, + ])("$name", ({ source, on, before, after }) => { + setup(); + if (before) usePreviewMiniPlayerStore.getState().open(ref, before); + settlePanelPreviewOnClose(ref, source, { + floatOnClose: on, + deviceState: deviceState({ sessions: [session] }), + }); + expect(miniPlayerSource()).toEqual(after); + }); +}); + describe("revealServerTabs", () => { const tab = (tabId: string, force?: boolean): PreviewSessionSnapshot => ({ threadId: "thread-1", diff --git a/apps/web/src/components/preview/agentOpenedPreviews.ts b/apps/web/src/components/preview/agentOpenedPreviews.ts index 8255cc48a551..4eb9e11b4959 100644 --- a/apps/web/src/components/preview/agentOpenedPreviews.ts +++ b/apps/web/src/components/preview/agentOpenedPreviews.ts @@ -16,6 +16,7 @@ import { getClientSettings } from "../../hooks/useSettings"; import { browserMiniPlayerSource, type PreviewMiniPlayerSource, + previewMiniPlayerSourceKey, usePreviewMiniPlayerStore, } from "../../previewMiniPlayerStore"; import { @@ -213,6 +214,28 @@ export function floatDeviceSurface( usePreviewMiniPlayerStore.getState().open(threadRef, source); } +/** + * Floats a panel's browser or device as the panel closes. With that off, a + * float hidden behind the panel tab closes too, or it would reappear. + */ +export function settlePanelPreviewOnClose( + threadRef: ScopedThreadRef, + source: PreviewMiniPlayerSource, + options: { readonly floatOnClose: boolean; readonly deviceState: DeviceServiceState | null }, +): void { + const miniPlayer = usePreviewMiniPlayerStore.getState(); + if (!options.floatOnClose) { + const current = miniPlayer.byThreadKey[scopedThreadKey(threadRef)]?.source; + if (current && previewMiniPlayerSourceKey(current) === previewMiniPlayerSourceKey(source)) { + miniPlayer.close(threadRef); + } + } else if (source.kind === "browser") { + miniPlayer.open(threadRef, source); + } else { + floatDeviceSurface(threadRef, source, options.deviceState); + } +} + export function resetDeviceSessionBaselinesForTests(): void { deviceSessionBaselines.clear(); } diff --git a/apps/web/src/components/settings/IntegrationsSettings.tsx b/apps/web/src/components/settings/IntegrationsSettings.tsx index 8edea7c6fccc..805e89ee7bce 100644 --- a/apps/web/src/components/settings/IntegrationsSettings.tsx +++ b/apps/web/src/components/settings/IntegrationsSettings.tsx @@ -15,6 +15,7 @@ import { BROWSER_PROFILE_NAME_MAX_LENGTH, BROWSER_RECORDING_FRAME_RATES, DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW, + DEFAULT_BROWSER_FLOAT_PREVIEW_ON_PANEL_CLOSE, DEFAULT_BROWSER_PROFILE_ID, DEFAULT_BROWSER_LINK_TARGET, DEFAULT_BROWSER_RECORDING_FRAME_RATE, @@ -1107,6 +1108,39 @@ function BrowserAutoShowFloatingPreviewSetting({ disabled }: { readonly disabled ); } +function BrowserFloatPreviewOnPanelCloseSetting() { + const floatOnClose = useClientSettings((settings) => settings.browserFloatPreviewOnPanelClose); + const updateSettings = useUpdatePrimarySettings(); + + return ( + + updateSettings({ + browserFloatPreviewOnPanelClose: DEFAULT_BROWSER_FLOAT_PREVIEW_ON_PANEL_CLOSE, + }) + } + /> + ) : null + } + control={ + + updateSettings({ browserFloatPreviewOnPanelClose: Boolean(checked) }) + } + aria-label="Float preview on panel close" + /> + } + /> + ); +} + function BrowserProfilesSetting({ disabled }: { readonly disabled: boolean }) { const userProfiles = useClientSettings((settings) => settings.browserProfiles); const defaultProfileId = useClientSettings((settings) => settings.browserDefaultProfileId); @@ -1591,6 +1625,8 @@ export function BrowserSettingsPanel() { + {/* Not desktop-only: web clients float server-run browsers and devices too. */} + {/* Not desktop-only: web clients search from server-run browser tabs too. */} ; @@ -162,6 +163,10 @@ export function getChangedBrowserSettingLabels(settings: BrowserDefaultSettings) DEFAULT_UNIFIED_SETTINGS.browserAutoShowFloatingPreview ? ["Floating preview"] : []), + ...(settings.browserFloatPreviewOnPanelClose !== + DEFAULT_UNIFIED_SETTINGS.browserFloatPreviewOnPanelClose + ? ["Float preview on panel close"] + : []), ...(settings.pullRequestLinksOpenInApp !== DEFAULT_UNIFIED_SETTINGS.pullRequestLinksOpenInApp ? ["Open pull requests in T3 Code"] : []), diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index 3dc9566e8981..550ff68bfecd 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -706,6 +706,7 @@ export function useSettingsRestore(onRestored?: () => void) { browserSearchEngine: DEFAULT_UNIFIED_SETTINGS.browserSearchEngine, browserCustomSearchUrl: DEFAULT_UNIFIED_SETTINGS.browserCustomSearchUrl, browserAutoShowFloatingPreview: DEFAULT_UNIFIED_SETTINGS.browserAutoShowFloatingPreview, + browserFloatPreviewOnPanelClose: DEFAULT_UNIFIED_SETTINGS.browserFloatPreviewOnPanelClose, pullRequestLinksOpenInApp: DEFAULT_UNIFIED_SETTINGS.pullRequestLinksOpenInApp, enableAgentBrowserAccess: DEFAULT_UNIFIED_SETTINGS.enableAgentBrowserAccess, }); diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts index 4f61ba41c0d8..671bc589a763 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -1087,6 +1087,12 @@ export const SETTINGS_SEARCH_ITEMS = [ to: "/settings/browser", searchTerms: ["agent opens browser device simulator pop into view hide"], }, + { + id: "browser-float-preview-on-panel-close", + title: "Float preview on panel close", + to: "/settings/browser", + searchTerms: ["close right panel browser device floating window mini player hide"], + }, { id: "automatic-pull", title: "Automatically pull", diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index 346213992e4b..f2a28c181c8c 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -301,6 +301,7 @@ export type DefaultThemePreference = typeof DefaultThemePreference.Type; export const DEFAULT_BROWSER_VIEWPORT: PreviewViewportSetting = FILL_PREVIEW_VIEWPORT; export const DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW = true; +export const DEFAULT_BROWSER_FLOAT_PREVIEW_ON_PANEL_CLOSE = true; export { BROWSER_RECORDING_FRAME_RATES, BrowserRecordingFrameRate, @@ -445,6 +446,10 @@ export const ClientSettingsSchema = Schema.Struct({ Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW)), ), + browserFloatPreviewOnPanelClose: Schema.Boolean.pipe( + Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_FLOAT_PREVIEW_ON_PANEL_CLOSE)), + ), + browserProfiles: Schema.Array(BrowserProfile).pipe( Schema.withDecodingDefault(Effect.succeed([])), ), @@ -2000,6 +2005,7 @@ export const ClientSettingsPatch = Schema.Struct({ browserSearchEngine: Schema.optionalKey(BrowserSearchEngine), browserCustomSearchUrl: Schema.optionalKey(BrowserCustomSearchUrl), browserAutoShowFloatingPreview: Schema.optionalKey(Schema.Boolean), + browserFloatPreviewOnPanelClose: Schema.optionalKey(Schema.Boolean), browserProfiles: Schema.optionalKey(Schema.Array(BrowserProfile)), browserDefaultProfileId: Schema.optionalKey(BrowserProfileId), confirmQuit: Schema.optionalKey(QuitConfirmationMode),