@devries-cameron20 / t3code Mirror · read-only / commits / f6dedece5a
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 23, 00:30 UTC

fix(server): Device panel Portrait and Landscape no longer swap on Android tablets (#20182)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

shivam committed Oct 20, 2026 at 06:10 UTC f6dedece5a43abe4e7e3ce34c844be32e642e8fb
2 files changed +50 -9
apps/server/src/device/DeviceActions.test.ts
+26 -7
@@ -113,18 +113,37 @@ describe("runDeviceAction", () => {
113 "acceleration",
114 "9.81:0:0",
115 ]);
116 - const phone = makeReady();
116 + // A device that refuses `wm size` keeps the portrait-native mapping.
117 + const phone = makeReady((call) =>
118 + call.args.join(" ").endsWith("shell wm size") ? { code: 1 } : {},
119 + );
120 yield* runDeviceAction(phone.ready, "android", {
121 type: "setOrientation",
122 deviceId: "R5CT1234",
123 value: "landscape_right",
124 });
122 - expect(phone.calls).toEqual([
123 - {
124 - command: "adb",
125 - args: ["-s", "R5CT1234", "shell", "cmd", "window", "user-rotation", "lock", "3"],
126 - },
127 - ]);
125 + expect(phone.calls.at(-1)).toEqual({
126 + command: "adb",
127 + args: ["-s", "R5CT1234", "shell", "cmd", "window", "user-rotation", "lock", "3"],
128 + });
129 + }),
130 + );
131 +
132 + it.effect.each([
133 + ["emulator-5554", "Physical size: 2560x1600", "portrait", "-9.81:0:0"],
134 + ["emulator-5554", "Physical size: 2560x1600", "landscape_left", "0:9.81:0"],
135 + ["R5CT1234", "Physical size: 2560x1600", "portrait", "3"],
136 + ["R5CT1234", "Physical size: 2560x1600", "landscape_left", "0"],
137 + ["R5CT1234", "Physical size: 1080x1920\nOverride size: 1920x1080", "portrait", "3"],
138 + ] as const)(
139 + "rotates from the natural orientation reported by wm size: %s %j %s",
140 + ([deviceId, wmSize, value, expected]) =>
141 + Effect.gen(function* () {
142 + const { ready, calls } = makeReady((call) =>
143 + call.args.join(" ").endsWith("shell wm size") ? { stdout: `${wmSize}\n` } : {},
144 + );
145 + yield* runDeviceAction(ready, "android", { type: "setOrientation", deviceId, value });
146 + expect(calls.at(-1)?.args.at(-1)).toBe(expected);
147 }),
148 );
149
apps/server/src/device/DeviceActions.ts
+24 -2
@@ -154,6 +154,9 @@ const ANDROID_PERMISSIONS: Record<string, ReadonlyArray<string>> = {
154 motion: ["android.permission.ACTIVITY_RECOGNITION"],
155 };
156
157 +// Android numbers rotations from the display's natural orientation and the emulator's accelerometer
158 +// reports gravity in that same frame, so both tables are keyed by the orientation a portrait-native
159 +// device shows at each rotation.
160 const ANDROID_GRAVITY: Record<DeviceOrientation, string> = {
161 portrait: "0:9.81:0",
162 landscape_left: "9.81:0:0",
@@ -166,6 +169,21 @@ const ANDROID_ROTATION: Record<DeviceOrientation, string> = {
169 portrait_upside_down: "2",
170 landscape_right: "3",
171 };
172 +// A landscape-native tablet sits a quarter turn further along that sequence: its portrait is
173 +// rotation 3 and its landscape is rotation 0.
174 +const ANDROID_LANDSCAPE_NATIVE_ROTATION: Record<DeviceOrientation, DeviceOrientation> = {
175 + portrait: "landscape_right",
176 + landscape_left: "portrait",
177 + portrait_upside_down: "landscape_left",
178 + landscape_right: "portrait_upside_down",
179 +};
180 +
181 +// `wm size` reports the natural-orientation size; an `Override size:` line is what the window
182 +// manager uses and is printed after `Physical size:`.
183 +const isLandscapeNative = (wmSize: string | undefined) => {
184 + const size = wmSize ? [...wmSize.matchAll(/size: (\d+)x(\d+)/g)].at(-1) : undefined;
185 + return size !== undefined && Number(size[1]) > Number(size[2]);
186 +};
187
188 export const runDeviceAction = Effect.fn("DeviceActions.run")(function* (
189 ready: DeviceHostReady,
@@ -370,6 +388,10 @@ const runAndroid = Effect.fn("DeviceActions.runAndroid")(function* (
388 reason: "unsupported",
389 });
390 case "setOrientation": {
391 + const wmSize = yield* quiet(shell(["wm", "size"], "orientation"));
392 + const rotation = isLandscapeNative(wmSize)
393 + ? ANDROID_LANDSCAPE_NATIVE_ROTATION[input.value]
394 + : input.value;
395 // `user-rotation lock` only rotates window content on recent images; the display the
396 // encoder captures stays put. Tilting the emulator's accelerometer rotates it for real, so
397 // that is used whenever the target is an emulator.
@@ -379,13 +401,13 @@ const runAndroid = Effect.fn("DeviceActions.runAndroid")(function* (
401 yield* adb(
402 run,
403 serial,
382 - ["emu", "sensor", "set", "acceleration", ANDROID_GRAVITY[input.value]],
404 + ["emu", "sensor", "set", "acceleration", ANDROID_GRAVITY[rotation]],
405 "orientation",
406 );
407 return;
408 }
409 yield* shell(
388 - ["cmd", "window", "user-rotation", "lock", ANDROID_ROTATION[input.value]],
410 + ["cmd", "window", "user-rotation", "lock", ANDROID_ROTATION[rotation]],
411 "orientation",
412 );
413 return;