fix(linux): tighten portal source fallback routing

This commit is contained in:
wiiiii123
2026-05-29 01:05:21 +07:00
parent 067070d405
commit 532d194e27
5 changed files with 46 additions and 4 deletions
+23 -1
View File
@@ -17,16 +17,28 @@ describe("getScreenSourceIdForDisplay", () => {
).toBe("screen:42:0");
});
it("routes unmatched Linux screens through the portal sentinel", () => {
it("routes unmatched Linux Wayland screens through the portal sentinel", () => {
expect(
getScreenSourceIdForDisplay({
displayId: "42",
env: { XDG_SESSION_TYPE: "wayland", WAYLAND_DISPLAY: "wayland-0" },
matchedSourceId: null,
platform: "linux",
}),
).toBe(LINUX_PORTAL_SCREEN_SOURCE_ID);
});
it("keeps unmatched Linux X11 screens on the explicit fallback id", () => {
expect(
getScreenSourceIdForDisplay({
displayId: "42",
env: { XDG_SESSION_TYPE: "x11", DISPLAY: ":0" },
matchedSourceId: null,
platform: "linux",
}),
).toBe("screen:fallback:42");
});
it("keeps non-Linux unmatched screens on the explicit fallback id", () => {
expect(
getScreenSourceIdForDisplay({
@@ -59,6 +71,16 @@ describe("shouldUseSyntheticLinuxPortalSource", () => {
).toBe(false);
});
it("recovers stale fallback ids through the synthetic path on Wayland", () => {
expect(
shouldUseSyntheticLinuxPortalSource({
env: { WAYLAND_DISPLAY: "wayland-0" },
platform: "linux",
sourceId: "screen:fallback:0",
}),
).toBe(true);
});
it("defaults unknown Linux sessions with WAYLAND_DISPLAY to the synthetic path", () => {
expect(
shouldUseSyntheticLinuxPortalSource({
+8 -2
View File
@@ -14,10 +14,12 @@ export function isLikelyLinuxWaylandSession(env: NodeJS.ProcessEnv) {
export function getScreenSourceIdForDisplay({
displayId,
env = process.env,
matchedSourceId,
platform,
}: {
displayId: string;
env?: NodeJS.ProcessEnv;
matchedSourceId?: string | null;
platform: NodeJS.Platform | string;
}) {
@@ -25,7 +27,7 @@ export function getScreenSourceIdForDisplay({
return matchedSourceId;
}
if (platform === "linux") {
if (platform === "linux" && isLikelyLinuxWaylandSession(env)) {
return LINUX_PORTAL_SCREEN_SOURCE_ID;
}
@@ -45,7 +47,11 @@ export function shouldUseSyntheticLinuxPortalSource({
return false;
}
if (sourceId && sourceId !== LINUX_PORTAL_SCREEN_SOURCE_ID) {
if (
sourceId &&
sourceId !== LINUX_PORTAL_SCREEN_SOURCE_ID &&
!sourceId.startsWith("screen:fallback:")
) {
return false;
}
+1
View File
@@ -128,6 +128,7 @@ export function registerSourceHandlers({
return {
id: getScreenSourceIdForDisplay({
displayId,
env: process.env,
matchedSourceId: matchedSource?.id,
platform: process.platform,
}),
+10 -1
View File
@@ -212,7 +212,7 @@ describe("shouldUseLinuxPortalCapture", () => {
it("uses the portal when the selected source is the Linux sentinel", () => {
expect(
shouldUseLinuxPortalCapture({
browserCaptureSourceId: "screen:0:0",
browserCaptureSourceId: "screen:linux-portal",
selectedSourceId: "screen:linux-portal",
}),
).toBe(true);
@@ -235,6 +235,15 @@ describe("shouldUseLinuxPortalCapture", () => {
}),
).toBe(false);
});
it("prefers a live Electron source over stale portal selection state", () => {
expect(
shouldUseLinuxPortalCapture({
browserCaptureSourceId: "screen:42:0",
selectedSourceId: "screen:linux-portal",
}),
).toBe(false);
});
});
describe("getScreenCaptureCursorSetting", () => {
+4
View File
@@ -135,6 +135,10 @@ export function shouldUseLinuxPortalCapture({
browserCaptureSourceId?: string;
selectedSourceId?: string;
}) {
if (browserCaptureSourceId && browserCaptureSourceId !== LINUX_PORTAL_SOURCE.id) {
return false;
}
return (
selectedSourceId === LINUX_PORTAL_SOURCE.id ||
browserCaptureSourceId === LINUX_PORTAL_SOURCE.id