The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 23:15 UTC
feat(mobile): close browser tabs from the Browser page (#19579)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Tristan Knight committed
Oct 20, 2026 at 05:22 UTC
32c9304436790f678e729f3b1a0bf830d2016415
4 files changed
+56
-9
apps/mobile/src/features/browser/BrowserPreviewRouteScreen.tsx
+1
-1
@@ -271,7 +271,7 @@ function BrowserAddressBar({
271
<BrowserTabMenu
272
environmentId={environmentId}
273
tab={tab}
274
- disabled={!streaming}
274
+ streaming={streaming}
275
onPaste={ready ? onPaste : undefined}
276
/>
277
</View>
apps/mobile/src/features/browser/BrowserTabMenu.tsx
+23
-8
@@ -1,4 +1,5 @@
1
import * as Dialog from "../../components/ui/Dialog";
2
+import { useAtomValue } from "@effect/atom-react";
3
import type { MenuAction } from "@react-native-menu/menu";
4
import {
5
DEFAULT_PREVIEW_ZOOM_FACTOR,
@@ -40,16 +41,18 @@ const VIEWPORTS = [
41
export function BrowserTabMenu({
42
environmentId,
43
tab,
43
- disabled,
44
+ streaming,
45
onPaste,
46
}: {
47
readonly environmentId: EnvironmentId;
48
readonly tab: PreviewSessionSnapshot;
48
- readonly disabled: boolean;
49
+ readonly streaming: boolean;
50
readonly onPaste?: () => void;
51
}) {
52
const adjust = useAtomCommand(previewEnvironment.adjust, "browser tab change");
53
const resize = useAtomCommand(previewEnvironment.resize, "browser viewport change");
54
+ const close = useAtomCommand(previewEnvironment.close, "browser tab close");
55
+ const canClose = useAtomValue(previewEnvironment.close.permissionAtom(environmentId));
56
const target = { threadId: tab.threadId as PreviewAdjustInput["threadId"], tabId: tab.tabId };
57
const colorScheme = tab.colorScheme ?? "system";
58
const zoomFactor = tab.zoomFactor ?? DEFAULT_PREVIEW_ZOOM_FACTOR;
@@ -65,6 +68,12 @@ export function BrowserTabMenu({
68
? `preset:${tab.viewport.presetId}`
69
: "custom";
70
71
+ const closeAction: MenuAction = {
72
+ id: "close",
73
+ title: "Close tab",
74
+ image: "xmark",
75
+ attributes: { destructive: true, disabled: !canClose },
76
+ };
77
const actions: MenuAction[] = [
78
...(onPaste ? [{ id: "paste", title: "Paste", image: "doc.on.clipboard" }] : []),
79
{ id: "hard-reload", title: "Hard reload", image: "arrow.clockwise.circle" },
@@ -107,6 +116,7 @@ export function BrowserTabMenu({
116
{ id: "clear:cache", title: "Clear cache", attributes: { destructive: true } },
117
],
118
},
119
+ closeAction,
120
];
121
122
const run = async (change: Omit<PreviewAdjustInput, "threadId" | "tabId">) => {
@@ -115,6 +125,12 @@ export function BrowserTabMenu({
125
};
126
127
const onAction = (id: string) => {
128
+ if (id === "close") {
129
+ void close({ environmentId, input: target }).then((result) => {
130
+ if (result._tag === "Failure") Dialog.alert("Could not close this browser tab");
131
+ });
132
+ return;
133
+ }
134
if (id === "paste") return onPaste?.();
135
if (id === "hard-reload") return void run({ hardReload: true });
136
if (id === "zoom:in") return void run({ zoomFactor: zoomTo(1) });
@@ -138,19 +154,18 @@ export function BrowserTabMenu({
154
}
155
};
156
141
- const pill = (
142
- <ControlPill icon="ellipsis" accessibilityLabel="Browser tab options" disabled={disabled} />
143
- );
144
- if (disabled) return pill;
157
return (
158
<Menu
159
+ // Remount when streaming changes, so an open menu never keeps offering
160
+ // the other state's actions.
161
+ key={streaming ? "streaming" : "idle"}
162
accessible
163
accessibilityLabel="Browser tab options"
164
accessibilityRole="button"
150
- actions={actions}
165
+ actions={streaming ? actions : [closeAction]}
166
onPressAction={({ nativeEvent }) => onAction(nativeEvent.event)}
167
>
153
- {pill}
168
+ <ControlPill icon="ellipsis" accessibilityLabel="Browser tab options" />
169
</Menu>
170
);
171
}
packages/client-runtime/src/state/commandPermissions.test.ts
+30
@@ -8,6 +8,7 @@ import { describe, expect, it } from "@effect/vitest";
8
import { vi } from "vite-plus/test";
9
import {
10
AuthOrchestrationOperateScope,
11
+ AuthPreviewOperateScope,
12
AuthSettingsWriteScope,
13
AuthSourceControlWriteScope,
14
ThreadId,
@@ -59,6 +60,35 @@ const setup = Effect.gen(function* () {
60
});
61
62
describe("command permissions", () => {
63
+ it.effect("requires the destination preview grant to close a browser tab", () =>
64
+ Effect.scoped(
65
+ Effect.gen(function* () {
66
+ const registry = yield* setup;
67
+ const close = createCommandPermissions(runtime, WS_METHODS.previewClose);
68
+ registry.set(sessions(env), AsyncResult.success(grant(true)));
69
+ expect(registry.get(close.permissionAtom(env))).toBe(false);
70
+ expect((yield* close.authorize(registry, env).pipe(Effect.flip))._tag).toBe(
71
+ "EnvironmentAuthorizationError",
72
+ );
73
+ registry.set(
74
+ sessions(env),
75
+ AsyncResult.success({
76
+ ...grant(false),
77
+ scopes: [AuthPreviewOperateScope],
78
+ permissions: [AuthPreviewOperateScope],
79
+ }),
80
+ );
81
+ expect(registry.get(close.permissionAtom(env))).toBe(true);
82
+ yield* close.authorize(registry, env);
83
+ registry.set(sessions(other), AsyncResult.success(grant(false)));
84
+ expect(registry.get(close.permissionAtom(other))).toBe(false);
85
+ expect((yield* close.authorize(registry, other).pipe(Effect.flip))._tag).toBe(
86
+ "EnvironmentAuthorizationError",
87
+ );
88
+ }),
89
+ ),
90
+ );
91
+
92
it.effect("requires the destination settings grant to run storage cleanup", () =>
93
Effect.scoped(
94
Effect.gen(function* () {
packages/contracts/src/clientRpcPermissions.ts
+2
@@ -2,6 +2,7 @@ import * as Schema from "effect/Schema";
2
import { GitPreparePullRequestThreadInput } from "./git.ts";
3
import {
4
AuthOrchestrationOperateScope,
5
+ AuthPreviewOperateScope,
6
AuthSettingsWriteScope,
7
AuthSourceControlWriteScope,
8
type AuthEnvironmentScope,
@@ -11,6 +12,7 @@ import { WS_METHODS } from "./rpc.ts";
12
13
/** Incremental client enforcement; the server still authorizes every request. */
14
export const CLIENT_GUARDED_RPC_SCOPES = {
15
+ [WS_METHODS.previewClose]: AuthPreviewOperateScope,
16
[WS_METHODS.serverRunStorageCleanup]: AuthSettingsWriteScope,
17
[WS_METHODS.serverCheckOtlpEndpoint]: AuthSettingsWriteScope,
18
[WS_METHODS.pullRequestsRunAction]: AuthSourceControlWriteScope,