@devries-cameron20 / t3code-1 / commits / 3d00499936
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

perf(desktop): stop decoding snapshots twice for accessibility (#19221)

Akshar Patel committed Oct 25, 2026 at 08:49 UTC 3d004999362848ae33b6f40e4bbd33b9d5c0ea59
2 files changed +26 -10
apps/desktop/src/snapShot/DesktopSnapShot.test.ts
+21 -6
@@ -1048,9 +1048,15 @@ it.effect("matches Windows accessibility windows on a scaled display", () => {
1048 );
1049 });
1050
1051 -it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
1052 - "persists %s text without inventing AT-SPI screen coordinates",
1053 - (backend) => {
1051 +it.effect.each([
1052 + { backend: "gnome", screenshot: "PNG" },
1053 + { backend: "niri", screenshot: "PNG" },
1054 + { backend: "kde", screenshot: "PNG" },
1055 + { backend: "hyprland", screenshot: "PNG" },
1056 + { backend: "gnome", screenshot: "invalid" },
1057 +] as const)(
1058 + "persists $backend accessibility text with a $screenshot screenshot",
1059 + ({ backend, screenshot }) => {
1060 vi.stubEnv("XDG_SESSION_TYPE", "wayland");
1061 flashWindows.length = 0;
1062 const window = {
@@ -1067,7 +1073,16 @@ it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
1073 ...(backend === "niri" ? { accessibilityBoundsReliable: false } : {}),
1074 ...(backend === "kde" ? { clientBounds: { x: 479, y: 371, width: 700, height: 520 } } : {}),
1075 };
1070 - linuxCaptureMock.mockResolvedValueOnce({ png: Buffer.from([1, 2, 3]), window });
1076 + // The captured pixels differ from the compositor's logical window bounds.
1077 + const imageSize = screenshot === "PNG" ? { width: 1400, height: 1040 } : window.bounds;
1078 + const png =
1079 + screenshot === "PNG"
1080 + ? Buffer.from(
1081 + "iVBORw0KGgoAAAANSUhEUgAABXgAAAQQAQAAAABwoA4ZAAAAyElEQVR4nO3BMQEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHgYyx4AAepc/c0AAAAASUVORK5CYII=",
1082 + "base64",
1083 + )
1084 + : Buffer.from([1, 2, 3]);
1085 + linuxCaptureMock.mockResolvedValueOnce({ png, window });
1086 activeWindowMock.mockClear();
1087 getSourcesMock.mockClear();
1088 accessibilityByPidMock.mockReset().mockResolvedValue({
@@ -1107,7 +1122,7 @@ it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
1122 assert.deepInclude(saved.source.accessibility, {
1123 format: "element-tree",
1124 coordinateSpace: "captured-image",
1110 - imageSize: { width: 700, height: window.bounds.height },
1125 + imageSize: { width: imageSize.width, height: imageSize.height },
1126 truncated: false,
1127 });
1128 assert.deepInclude(
@@ -1117,7 +1132,7 @@ it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
1132 {
1133 role: "window",
1134 name: "Editor",
1120 - bounds: { x: 0, y: 0, width: 700, height: window.bounds.height },
1135 + bounds: { x: 0, y: 0, width: imageSize.width, height: imageSize.height },
1136 state: { active: true },
1137 },
1138 );
apps/desktop/src/snapShot/DesktopSnapShot.ts
+5 -4
@@ -90,6 +90,7 @@ import {
90 snapShotShortcutSystemConflict,
91 } from "./snapShot.ts";
92 import * as HostProcess from "@t3tools/shared/HostProcess";
93 +import { readImageDimensions } from "@t3tools/shared/imageDimensions";
94
95 const MAX_CAPTURE_WIDTH = 2_560;
96 const MAX_CAPTURE_HEIGHT = 1_600;
@@ -413,10 +414,10 @@ async function requestMacSnapShotPermissions(
414 }
415
416 function snapShotImageSize(png: Buffer, fallback: Electron.Rectangle): Electron.Size {
416 - try {
417 - const size = Electron.nativeImage.createFromBuffer(png).getSize();
418 - if (size.width > 0 && size.height > 0) return size;
419 - } catch {}
417 + // Capture backends already validate or encode the PNG. Reading its header
418 + // avoids decoding every pixel again just to size accessibility coordinates.
419 + const size = readImageDimensions(png);
420 + if (size) return size;
421 return {
422 width: Math.max(1, Math.round(fallback.width)),
423 height: Math.max(1, Math.round(fallback.height)),