Skip to content

Commit cd8fc91

Browse files
fix(web): don't offer VS Code on iPad, iPhone and Android browsers (pingdotgg#27557)
1 parent 1c65ad0 commit cd8fc91

5 files changed

Lines changed: 79 additions & 6 deletions

File tree

‎apps/web/src/components/chat/OpenInPicker.browser.test.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,25 @@ describe("remote editor links", () => {
202202
expect(state.openUrl).toHaveBeenCalledWith(expect.stringContaining("ssh-remote+sol"));
203203
expect(state.run).not.toHaveBeenCalled();
204204
});
205+
206+
it("explains why a phone or tablet browser has no editor to open", async () => {
207+
await using fixture = await setup();
208+
const { renderPicker, byLabel, primaryButton, menuItems, click, pressOpenFavorite } = fixture;
209+
state.remote = { mode: "remote-links", host: { kind: "ssh-alias", host: "sol" } };
210+
state.clientEditors = [];
211+
await renderPicker();
212+
213+
expect(primaryButton().disabled).toBe(true);
214+
expect((await pressOpenFavorite()).defaultPrevented).toBe(false);
215+
await click(byLabel("Choose editor"));
216+
await vi.waitFor(() =>
217+
expect(menuItems().map((item) => item.textContent)).toEqual([
218+
"Open from a computer to edit on Test host",
219+
]),
220+
);
221+
expect(menuItems()[0]!.getAttribute("aria-disabled")).toBe("true");
222+
expect(state.openUrl).not.toHaveBeenCalled();
223+
});
205224
});
206225

207226
describe("open in editor announcement", () => {

‎apps/web/src/components/chat/OpenInPicker.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,18 @@ export const OpenInPicker = memo(function OpenInPicker({
286286
const primaryOption = options.find(({ value }) => value === preferredEditor) ?? null;
287287
const primaryLabel = isPanel ? `Open in ${primaryOption?.label ?? "editor"}` : "Open";
288288

289+
const unavailableReason =
290+
remote.mode === "remote-unavailable"
291+
? `No SSH route to ${environmentLabel}`
292+
: remote.mode === "remote-links" && options.length === 0
293+
? `Open from a computer to edit on ${environmentLabel}`
294+
: null;
295+
289296
const editorItems = (
290297
<>
291-
{remote.mode === "remote-unavailable" ? (
298+
{unavailableReason !== null ? (
292299
<MenuItem density={presentation === "menu" ? "touch" : "default"} disabled>
293-
No SSH route to {environmentLabel}
300+
{unavailableReason}
294301
</MenuItem>
295302
) : (
296303
<>

‎apps/web/src/connection/clientMetadata.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
DesktopBridge,
66
} from "@t3tools/contracts";
77

8-
interface BrowserIdentity {
8+
export interface BrowserIdentity {
99
readonly userAgent: string;
1010
readonly platform: string;
1111
readonly maxTouchPoints: number;
@@ -32,7 +32,7 @@ function isIpadosDesktopUserAgent(identity: BrowserIdentity): boolean {
3232
);
3333
}
3434

35-
function browserClientOs(identity: BrowserIdentity): ClientOs {
35+
export function browserClientOs(identity: BrowserIdentity): ClientOs {
3636
const userAgent = identity.userAgent;
3737
if (userAgent.trim() === "") return "unknown";
3838
if (/iphone|ipad|ipod/i.test(userAgent) || isIpadosDesktopUserAgent(identity)) return "iOS";

‎apps/web/src/remoteOpen.test.ts‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { buildRemoteOpenUrl, EnvironmentId } from "@t3tools/contracts";
77
import { describe, expect, it } from "vite-plus/test";
88

9-
import { resolveRemoteOpenState } from "./remoteOpen";
9+
import { remoteFallbackEditors, resolveRemoteOpenState } from "./remoteOpen";
1010

1111
const environmentId = EnvironmentId.make("environment-1");
1212

@@ -179,6 +179,46 @@ describe("resolveRemoteOpenState", () => {
179179
});
180180
});
181181

182+
describe("remoteFallbackEditors", () => {
183+
it.each([
184+
{
185+
// iPadOS Safari requests the desktop site with a Macintosh user agent by default.
186+
device: "iPad with a desktop user agent",
187+
userAgent:
188+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
189+
platform: "MacIntel",
190+
maxTouchPoints: 5,
191+
},
192+
{
193+
device: "iPhone",
194+
userAgent:
195+
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1",
196+
platform: "iPhone",
197+
maxTouchPoints: 5,
198+
},
199+
{
200+
device: "Android phone",
201+
userAgent:
202+
"Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Mobile Safari/537.36",
203+
platform: "Linux armv81",
204+
maxTouchPoints: 5,
205+
},
206+
])("offers no desktop editor for remote links on an $device", ({ device: _, ...identity }) => {
207+
expect(remoteFallbackEditors(identity)).toEqual([]);
208+
});
209+
210+
it("keeps the VS Code fallback for remote links on a Mac", () => {
211+
expect(
212+
remoteFallbackEditors({
213+
userAgent:
214+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
215+
platform: "MacIntel",
216+
maxTouchPoints: 0,
217+
}),
218+
).toEqual(["vscode"]);
219+
});
220+
});
221+
182222
describe("buildRemoteOpenUrl", () => {
183223
it("roots Windows paths", () => {
184224
expect(

‎apps/web/src/remoteOpen.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as Schema from "effect/Schema";
1010
import { Atom } from "effect/reactivity";
1111
import { useAtomValue } from "@effect/atom-react";
1212

13+
import { browserClientOs, type BrowserIdentity } from "~/connection/clientMetadata";
1314
import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal";
1415
import { isLoopbackHostname } from "~/environments/primary/target";
1516
import { useLocalStorage } from "~/hooks/useLocalStorage";
@@ -149,6 +150,12 @@ export function useRemoteOpenState(environmentId: EnvironmentId | null): RemoteO
149150

150151
const REMOTE_FALLBACK_EDITORS: ReadonlyArray<EditorId> = ["vscode"];
151152

153+
// Phone and tablet browsers have no desktop editor to receive a vscode:// remote link.
154+
export function remoteFallbackEditors(identity: BrowserIdentity): ReadonlyArray<EditorId> {
155+
const os = browserClientOs(identity);
156+
return os === "iOS" || os === "Android" ? [] : REMOTE_FALLBACK_EDITORS;
157+
}
158+
152159
// Probed once per page: installed editors rarely change, and the probe spawns processes.
153160
const remoteCapableEditorsAtom = Atom.make((get): ReadonlyArray<EditorId> => {
154161
const probe = window.desktopBridge?.probeRemoteEditors;
@@ -159,7 +166,7 @@ const remoteCapableEditorsAtom = Atom.make((get): ReadonlyArray<EditorId> => {
159166
},
160167
() => undefined,
161168
);
162-
return REMOTE_FALLBACK_EDITORS;
169+
return remoteFallbackEditors(navigator);
163170
}).pipe(Atom.keepAlive, Atom.withLabel("remote-capable-editors"));
164171

165172
export function useRemoteCapableEditors(): ReadonlyArray<EditorId> {

0 commit comments

Comments
 (0)