diff --git a/apps/desktop/src/settings/DesktopClientSettings.test.ts b/apps/desktop/src/settings/DesktopClientSettings.test.ts index d66ca346aabb3..69663ef7b2291 100644 --- a/apps/desktop/src/settings/DesktopClientSettings.test.ts +++ b/apps/desktop/src/settings/DesktopClientSettings.test.ts @@ -29,6 +29,7 @@ const clientSettings: ClientSettings = { browserLinkTarget: "app", sideThreadOpenTarget: "main", 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 9a5e4c24e7a0c..022ea7a5bf91a 100644 --- a/apps/web/src/components/chat/useRightPanelActions.ts +++ b/apps/web/src/components/chat/useRightPanelActions.ts @@ -30,8 +30,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"; @@ -178,16 +179,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 dee29a16cf527..414c44df9dd5b 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 8255cc48a551d..4eb9e11b49595 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 197556552b4d8..2b3cd912b4ba6 100644 --- a/apps/web/src/components/settings/IntegrationsSettings.tsx +++ b/apps/web/src/components/settings/IntegrationsSettings.tsx @@ -16,6 +16,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, @@ -1180,6 +1181,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 searchableSetting = useSearchableSetting(); const gt = useGT(); @@ -1702,6 +1736,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. */} ; @@ -175,6 +176,10 @@ export function getChangedBrowserSettingLabels( DEFAULT_UNIFIED_SETTINGS.browserAutoShowFloatingPreview ? [resolve(msg("Floating preview"))] : []), + ...(settings.browserFloatPreviewOnPanelClose !== + DEFAULT_UNIFIED_SETTINGS.browserFloatPreviewOnPanelClose + ? ["Float preview on panel close"] + : []), ...(settings.pullRequestLinksOpenInApp !== DEFAULT_UNIFIED_SETTINGS.pullRequestLinksOpenInApp ? [resolve(msg("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 493d8a1e79565..bbf41a5d346d9 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -766,6 +766,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 4252fccc9c7d0..9bf03724ffef3 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -1207,6 +1207,12 @@ export const SETTINGS_SEARCH_ITEMS = [ to: "/settings/browser", searchTerms: [msg("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: msg("Automatically pull"), diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index b0726b07174c9..a1e996c80ca20 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -307,6 +307,7 @@ export type DefaultAppearancePreference = typeof DefaultAppearancePreference.Typ 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, @@ -464,6 +465,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([])), ), @@ -2079,6 +2084,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),