GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(desktop): stop decoding snapshots twice for accessibility (#19221) · Pipyakas/t3code@2efa0a4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/desktop/src/snapShot
    • DesktopSnapShot.test.ts
    • DesktopSnapShot.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/desktop/src/snapShot/DesktopSnapShot.test.ts‎

Copy file name to clipboardExpand all lines: apps/desktop/src/snapShot/DesktopSnapShot.test.ts
+21-6Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,15 @@ it.effect("matches Windows accessibility windows on a scaled display", () => {
10491049
);
10501050
});
10511051

1052-
it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
1053-
"persists %s text without inventing AT-SPI screen coordinates",
1054-
(backend) => {
1052+
it.effect.each([
1053+
{ backend: "gnome", screenshot: "PNG" },
1054+
{ backend: "niri", screenshot: "PNG" },
1055+
{ backend: "kde", screenshot: "PNG" },
1056+
{ backend: "hyprland", screenshot: "PNG" },
1057+
{ backend: "gnome", screenshot: "invalid" },
1058+
] as const)(
1059+
"persists $backend accessibility text with a $screenshot screenshot",
1060+
({ backend, screenshot }) => {
10551061
vi.stubEnv("XDG_SESSION_TYPE", "wayland");
10561062
flashWindows.length = 0;
10571063
const window = {
@@ -1068,7 +1074,16 @@ it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
10681074
...(backend === "niri" ? { accessibilityBoundsReliable: false } : {}),
10691075
...(backend === "kde" ? { clientBounds: { x: 479, y: 371, width: 700, height: 520 } } : {}),
10701076
};
1071-
linuxCaptureMock.mockResolvedValueOnce({ png: Buffer.from([1, 2, 3]), window });
1077+
// The captured pixels differ from the compositor's logical window bounds.
1078+
const imageSize = screenshot === "PNG" ? { width: 1400, height: 1040 } : window.bounds;
1079+
const png =
1080+
screenshot === "PNG"
1081+
? Buffer.from(
1082+
"iVBORw0KGgoAAAANSUhEUgAABXgAAAQQAQAAAABwoA4ZAAAAyElEQVR4nO3BMQEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHgYyx4AAepc/c0AAAAASUVORK5CYII=",
1083+
"base64",
1084+
)
1085+
: Buffer.from([1, 2, 3]);
1086+
linuxCaptureMock.mockResolvedValueOnce({ png, window });
10721087
activeWindowMock.mockClear();
10731088
getSourcesMock.mockClear();
10741089
accessibilityByPidMock.mockReset().mockResolvedValue({
@@ -1108,7 +1123,7 @@ it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
11081123
assert.deepInclude(saved.source.accessibility, {
11091124
format: "element-tree",
11101125
coordinateSpace: "captured-image",
1111-
imageSize: { width: 700, height: window.bounds.height },
1126+
imageSize: { width: imageSize.width, height: imageSize.height },
11121127
truncated: false,
11131128
});
11141129
assert.deepInclude(
@@ -1118,7 +1133,7 @@ it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
11181133
{
11191134
role: "window",
11201135
name: "Editor",
1121-
bounds: { x: 0, y: 0, width: 700, height: window.bounds.height },
1136+
bounds: { x: 0, y: 0, width: imageSize.width, height: imageSize.height },
11221137
state: { active: true },
11231138
},
11241139
);
Collapse file

‎apps/desktop/src/snapShot/DesktopSnapShot.ts‎

Copy file name to clipboardExpand all lines: apps/desktop/src/snapShot/DesktopSnapShot.ts
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
snapShotShortcutSystemConflict,
9191
} from "./snapShot.ts";
9292
import * as HostProcess from "@t3tools/shared/HostProcess";
93+
import { readImageDimensions } from "@t3tools/shared/imageDimensions";
9394

9495
const MAX_CAPTURE_WIDTH = 2_560;
9596
const MAX_CAPTURE_HEIGHT = 1_600;
@@ -418,10 +419,10 @@ async function requestMacSnapShotPermissions(
418419
}
419420

420421
function snapShotImageSize(png: Buffer, fallback: Electron.Rectangle): Electron.Size {
421-
try {
422-
const size = Electron.nativeImage.createFromBuffer(png).getSize();
423-
if (size.width > 0 && size.height > 0) return size;
424-
} catch {}
422+
// Capture backends already validate or encode the PNG. Reading its header
423+
// avoids decoding every pixel again just to size accessibility coordinates.
424+
const size = readImageDimensions(png);
425+
if (size) return size;
425426
return {
426427
width: Math.max(1, Math.round(fallback.width)),
427428
height: Math.max(1, Math.round(fallback.height)),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.