Skip to content

Commit 2e26c84

Browse files
committed
fix(linux): leave the ScreenCast portal to Wayland sessions
On X11, KDE's portal has no ScreenCast, so every take died on "CreateSession: Portal request didn't succeed: Other". Treat the portal helper as absent outside Wayland: capture falls back to Chromium, which X11 serves without a portal, and the cursor to screen telemetry. Refs #1491
1 parent fccd228 commit 2e26c84

4 files changed

Lines changed: 47 additions & 3 deletions

File tree

‎electron/native-bridge/capture/linuxNativeCaptureSession.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ async function record(sourceKind?: string) {
156156
}
157157

158158
beforeEach(() => {
159+
// The portal helper is only looked up in a Wayland session (#1491).
160+
vi.stubEnv("XDG_SESSION_TYPE", "wayland");
159161
helper = new FakeHelper();
160162
spawnMock.mockReset();
161163
spawnMock.mockReturnValue(helper as unknown as ReturnType<typeof spawn>);
@@ -169,6 +171,7 @@ beforeEach(() => {
169171

170172
afterEach(() => {
171173
vi.restoreAllMocks();
174+
vi.unstubAllEnvs();
172175
});
173176

174177
describe("LinuxNativeCaptureSession", () => {

‎electron/native-bridge/cursor/recording/factory.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Rectangle } from "electron";
2+
import { isWaylandSession } from "../../../wayland";
23
import { MacNativeCursorRecordingSession } from "./macNativeCursorRecordingSession";
34
import { PipeWireCursorRecordingSession } from "./pipeWireCursorRecordingSession";
45
import type { CursorRecordingSession } from "./session";
@@ -36,7 +37,7 @@ export function createCursorRecordingSession(
3637
});
3738
}
3839

39-
if (options.platform === "linux") {
40+
if (options.platform === "linux" && isWaylandSession(process.env)) {
4041
// The ScreenCast portal's METADATA cursor mode is the only source of a real
4142
// pointer position on Wayland: `screen.getCursorScreenPoint()` returns
4243
// {0,0} there, so TelemetryRecordingSession produced well-formed recordings
@@ -50,7 +51,7 @@ export function createCursorRecordingSession(
5051
});
5152
}
5253

53-
// Anything else (a future platform, or a test harness): capture cursor
54+
// Anything else (X11, a future platform, or a test harness): capture cursor
5455
// positions via Electron's `screen` API on an interval. No cursor
5556
// sprites/assets and no clicks, just position telemetry.
5657
return new TelemetryRecordingSession({

‎electron/native-bridge/cursor/recording/pipeWireCursorRecordingSession.test.ts‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ vi.mock("node:fs", async (importOriginal) => {
3333
});
3434

3535
import { spawn } from "node:child_process";
36-
import { PipeWireCursorRecordingSession } from "./pipeWireCursorRecordingSession";
36+
import { createCursorRecordingSession } from "./factory";
37+
import {
38+
findPipeWireCursorHelperPath,
39+
PipeWireCursorRecordingSession,
40+
} from "./pipeWireCursorRecordingSession";
41+
import { TelemetryRecordingSession } from "./telemetryRecordingSession";
3742

3843
/** Minimal stand-in for the helper process: stdio pipes plus kill bookkeeping. */
3944
class FakeHelper extends EventEmitter {
@@ -93,7 +98,13 @@ function flushStdout() {
9398
return new Promise((resolve) => setTimeout(resolve, 0));
9499
}
95100

101+
const realPlatform = process.platform;
102+
96103
beforeEach(() => {
104+
// The helper is only looked up in a Wayland session (#1491); pin one for the session tests.
105+
Object.defineProperty(process, "platform", { value: "linux" });
106+
vi.stubEnv("XDG_SESSION_TYPE", "wayland");
107+
vi.stubEnv("WAYLAND_DISPLAY", undefined);
97108
helper = new FakeHelper();
98109
spawnMock.mockReset();
99110
spawnMock.mockReturnValue(helper as unknown as ReturnType<typeof spawn>);
@@ -107,6 +118,30 @@ beforeEach(() => {
107118

108119
afterEach(() => {
109120
vi.restoreAllMocks();
121+
vi.unstubAllEnvs();
122+
Object.defineProperty(process, "platform", { value: realPlatform });
123+
});
124+
125+
describe("X11 session (#1491)", () => {
126+
const cursorOptions = {
127+
getDisplayBounds: () => null,
128+
maxSamples: 100,
129+
platform: "linux" as const,
130+
sampleIntervalMs: 33,
131+
};
132+
133+
it("finds the portal helper in a Wayland session", () => {
134+
expect(findPipeWireCursorHelperPath()).not.toBeNull();
135+
expect(createCursorRecordingSession(cursorOptions)).toBeInstanceOf(
136+
PipeWireCursorRecordingSession,
137+
);
138+
});
139+
140+
it("treats the helper as absent on X11, so capture falls back to Chromium", () => {
141+
vi.stubEnv("XDG_SESSION_TYPE", "x11");
142+
expect(findPipeWireCursorHelperPath()).toBeNull();
143+
expect(createCursorRecordingSession(cursorOptions)).toBeInstanceOf(TelemetryRecordingSession);
144+
});
110145
});
111146

112147
describe("PipeWireCursorRecordingSession", () => {

‎electron/native-bridge/cursor/recording/pipeWireCursorRecordingSession.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { accessSync, constants as fsConstants } from "node:fs";
33
import path from "node:path";
44
import type { Readable, Writable } from "node:stream";
55
import type { CursorRecordingData } from "../../../../src/native/contracts";
6+
import { isWaylandSession } from "../../../wayland";
67
import {
78
NdjsonLineReader,
89
PipeWireCursorAccumulator,
@@ -70,6 +71,10 @@ function helperCandidates() {
7071
}
7172

7273
export function findPipeWireCursorHelperPath() {
74+
// The helper is a ScreenCast portal client, and KDE's portal has no ScreenCast outside
75+
// Wayland: on X11 the take died on "CreateSession: ... Other" (#1491). Without the helper
76+
// every caller falls back to Chromium's capture, which X11 serves without a portal.
77+
if (!isWaylandSession(process.env)) return null;
7378
for (const candidate of helperCandidates()) {
7479
try {
7580
accessSync(candidate, fsConstants.X_OK);

0 commit comments

Comments
 (0)