@devries-cameron20 / t3code Mirror · read-only / commits / b02b436e26
Fork 0

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, 13:15 UTC

fix(server): preserve URL arguments in Android device actions (#25205)

Co-authored-by: Alex Southwell <4596216+saphid@users.noreply.github.com>

maria committed Oct 29, 2026 at 17:47 UTC b02b436e26f9c0c6c193ea2af22a50885ffe8aac
2 files changed +43 -1
apps/server/src/device/DeviceActions.test.ts
+38
@@ -1,5 +1,9 @@
1 +import * as NodeServices from "@effect/platform-node/NodeServices";
2 import { describe, expect, it } from "@effect/vitest";
3 +import * as HostProcess from "@t3tools/shared/HostProcess";
4 import * as Effect from "effect/Effect";
5 +import * as ChildProcess from "effect/process/ChildProcess";
6 +import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
7
8 import { readDeviceDetail, runDeviceAction } from "./DeviceActions.ts";
9 import type { DeviceHostReady } from "./DeviceHost.ts";
@@ -43,6 +47,40 @@ const makeReady = (
47 const udid = "SIM-1";
48
49 describe("runDeviceAction", () => {
50 + it.live.each([
51 + "https://example.com/callback?code=1&state=2",
52 + "https://example.com/it's?a=1&b=2",
53 + "https://example.com/a b?key=value",
54 + "https://example.com/plain",
55 + ])("opens the complete Android URL %s", (url) =>
56 + Effect.gen(function* () {
57 + if ((yield* HostProcess.Platform) === "win32") return;
58 + const { ready, calls } = makeReady();
59 + yield* runDeviceAction(ready, "android", {
60 + type: "openUrl",
61 + deviceId: "emulator-5554",
62 + url,
63 + });
64 + const args = calls[0]!.args;
65 + expect(args.slice(0, 3)).toEqual(["-s", "emulator-5554", "shell"]);
66 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
67 + // adb joins arguments verbatim before the Android shell parses them.
68 + const stdout = yield* spawner.string(
69 + ChildProcess.make("/bin/sh", [
70 + "-c",
71 + `am() { printf '%s\\0' "$@"; }\n${args.slice(3).join(" ")}`,
72 + ]),
73 + );
74 + expect(stdout.split("\0").slice(0, -1)).toEqual([
75 + "start",
76 + "-a",
77 + "android.intent.action.VIEW",
78 + "-d",
79 + url,
80 + ]);
81 + }).pipe(Effect.provide(NodeServices.layer)),
82 + );
83 +
84 it.effect.each([
85 ["emulator-5554", "Physical size: 2560x1600", "portrait", "-9.81:0:0"],
86 ["emulator-5554", "Physical size: 2560x1600", "landscape_left", "0:9.81:0"],
apps/server/src/device/DeviceActions.ts
+5 -1
@@ -342,13 +342,17 @@ const serveSimPermissions = Effect.fn("DeviceActions.serveSimPermissions")(funct
342 const adb = (run: Runner, serial: string, args: ReadonlyArray<string>, operation: string) =>
343 run("adb", ["-s", serial, ...args]).pipe(Effect.flatMap(ok(operation)));
344
345 +// adb shell joins arguments without escaping before the device's shell parses them.
346 +const androidShellWord = (value: string) =>
347 + /^[\w@%+=:,./-]+$/.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`;
348 +
349 const runAndroid = Effect.fn("DeviceActions.runAndroid")(function* (
350 run: Runner,
351 input: DeviceActionInput,
352 ) {
353 const serial = input.deviceId;
354 const shell = (args: ReadonlyArray<string>, operation: string) =>
351 - adb(run, serial, ["shell", ...args], operation);
355 + adb(run, serial, ["shell", ...args.map(androidShellWord)], operation);
356 switch (input.type) {
357 case "setAppearance":
358 yield* shell(["cmd", "uimode", "night", input.value === "dark" ? "yes" : "no"], "appearance");