fix(desktop): browser tab fixes for fullscreen, shortcuts, links, reload and hidden tabs #16961
Mergedjuliusmarmingemerged 22 commits into
main fromrefs/pull/16961/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/web/src/browser/openFileInPreview.ts lines 92 to 92OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -69,10 +80,13 @@6980 // maps the result differently, so the configured defaults have to be7081 // applied explicitly or file/link opens would ignore them.7182 viewport: browserDefaultOpenViewport(defaults),72- profileId: browserDefaultOpenProfileId(defaults),83+ profileId: input.profileId ?? browserDefaultOpenProfileId(defaults),7384 ...(runtime === undefined ? {} : { runtime }),7485 },7586 });7687 return mapAtomCommandResult(result, (snapshot) => {77- applyPreviewServerSnapshot(input.threadRef, snapshot);7888 rememberPreviewUrl(input.threadRef, input.url);89+ if (input.background) {90+ updatePreviewServerSnapshot(input.threadRef, snapshot);91+ // The server's "opened" event activates the new tab; hand focus back.92+ if (previousActiveTabId) setActivePreviewTab(input.threadRef, previousActiveTabId);apps/desktop/src/window/DesktopWindow.ts line 1042OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1027,3 +1037,6 @@10271037 // own zoom, so put each guest back where the preview left it.10281038 yield* previewManager.reapplyZoom();10291039 }),1040+ runMainContentsCommand: Effect.fn("desktop.window.runMainContentsCommand")(function* (command) {1041+ yield* Effect.annotateCurrentSpan({ command });1042+ const window = yield* focusedMainWindow;
- @@ -164,0 +229,21 @@229+ });230+ const shownUrl =231+ url.length > MAX_PROMPT_URL_LENGTH ? `${url.slice(0, MAX_PROMPT_URL_LENGTH)}…` : url;232+ runFork(233+ electronDialog234+ .showMessageBox({235+ type: "question",236+ buttons: ["Open", "Cancel"],237+ defaultId: 0,238+ cancelId: 1,239+ message: `Open this ${new URL(url).protocol.slice(0, -1)} link?`,240+ detail: `A page in the browser wants to open another application:\n\n${shownUrl}`,241+ })242+ .pipe(243+ Effect.map(({ response }) => response === 0),244+ Effect.orElseSucceed(() => false),245+ Effect.flatMap(settle),246+ Effect.onInterrupt(() => settle(false)),247+ ),248+ );249+ };
- @@ -69,10 +80,18 @@6980 // maps the result differently, so the configured defaults have to be7081 // applied explicitly or file/link opens would ignore them.7182 viewport: browserDefaultOpenViewport(defaults),72- profileId: browserDefaultOpenProfileId(defaults),83+ profileId: input.profileId ?? browserDefaultOpenProfileId(defaults),7384 ...(runtime === undefined ? {} : { runtime }),7485 },7586 });7687 return mapAtomCommandResult(result, (snapshot) => {77- applyPreviewServerSnapshot(input.threadRef, snapshot);7888 rememberPreviewUrl(input.threadRef, input.url);89+ if (input.background) {90+ updatePreviewServerSnapshot(input.threadRef, snapshot);91+ // The server's "opened" event activates the new tab; hand focus back,92+ // unless the user has picked another tab while the open was in flight.93+ if (94+ previousActiveTabId &&95+ readThreadPreviewState(input.threadRef).activeTabId === snapshot.tabId96+ ) {97+ setActivePreviewTab(input.threadRef, previousActiveTabId);
- @@ -190,3 +203,4 @@190203 tab.relay = null;191204 return;192205 }206+ if (AGENT_INPUT_COMMAND.test(command.value.message)) tab.agentInputAt = performance.now();@@ -3642,3 +3687,20 @@36423687 const browserSession = yield* BrowserSession.BrowserSession;36433688 const browserHost = yield* DesktopBrowserHost.DesktopBrowserHost;36443689 const downloadSessions = new WeakSet<Electron.Session>();3690+ const fileSystem = yield* FileSystem.FileSystem;3691+ const path = yield* Path.Path;3692+ const runForkDownload = Effect.runForkWith(yield* Effect.context<never>());3693+ /** Puts a copy in Downloads under a name that never replaces a file already there. */3694+ const copyToDownloads = Effect.fn("PreviewManager.copyToDownloads")(function* (3695+ source: string,3696+ fileName: string,3697+ ) {3698+ const directory = app.getPath("downloads");3699+ const extension = path.extname(fileName);3700+ const stem = path.basename(fileName, extension) || "download";3701+ for (let attempt = 0; attempt < 100; attempt += 1) {3702+ const target = path.join(3703+ directory,3704+ attempt === 0 ? `${stem}${extension}` : `${stem} (${attempt})${extension}`,3705+ );3706+ if (yield* fileSystem.exists(target)) continue;
- @@ -190,6 +203,10 @@190203 tab.relay = null;191204 return;192205 }206+ if (AGENT_INPUT_COMMAND.test(command.value.message)) tab.agentInputAt = performance.now();193207 relayFor(tab).receive(command.value.message);194208 });195209210+ const humanStartedDownload = (source: Electron.WebContents) => {211+ const tab = [...tabs.values()].find((candidate) => candidate.debuggee.webContents === source);212+ return tab !== undefined && performance.now() - tab.agentInputAt > AGENT_DOWNLOAD_WINDOW_MS;@@ -3642,3 +3687,21 @@36423687 const browserSession = yield* BrowserSession.BrowserSession;36433688 const browserHost = yield* DesktopBrowserHost.DesktopBrowserHost;36443689 const downloadSessions = new WeakSet<Electron.Session>();3690+ const fileSystem = yield* FileSystem.FileSystem;3691+ const path = yield* Path.Path;3692+ const runForkDownload = Effect.runForkWith(yield* Effect.context<never>());3693+ /** Puts a copy in Downloads under a name that never replaces a file already there. */3694+ const copyToDownloads = Effect.fn("PreviewManager.copyToDownloads")(function* (3695+ source: string,3696+ fileName: string,3697+ ) {3698+ const directory = app.getPath("downloads");3699+ const extension = path.extname(fileName);3700+ const stem = path.basename(fileName, extension) || "download";3701+ for (let attempt = 0; attempt < 100; attempt += 1) {3702+ const target = path.join(3703+ directory,3704+ attempt === 0 ? `${stem}${extension}` : `${stem} (${attempt})${extension}`,3705+ );3706+ if (yield* fileSystem.exists(target)) continue;3707+ yield* fileSystem.copyFile(source, target);
juliusmarminge merged thisd9f7c0c
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
48b71f0· PR result:f3bbe7f· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.