fix(linux): ignore invalid ozone overrides

This commit is contained in:
wiiiii123
2026-04-22 17:46:20 +07:00
parent be8c5ef821
commit 4420ce6636
2 changed files with 21 additions and 8 deletions
+10
View File
@@ -21,6 +21,16 @@ describe("shouldForceLinuxEgl", () => {
).toBe(false);
});
it("falls back to Electron's ozone hint when OZONE_PLATFORM is invalid", () => {
expect(
shouldForceLinuxEgl({
OZONE_PLATFORM: "auto",
ELECTRON_OZONE_PLATFORM_HINT: "wayland",
XDG_SESSION_TYPE: "x11",
}),
).toBe(false);
});
it("forces EGL in an X11 session", () => {
expect(shouldForceLinuxEgl({ XDG_SESSION_TYPE: "x11" })).toBe(true);
});
+11 -8
View File
@@ -4,19 +4,22 @@ export interface GpuSwitches {
disableFeatures?: string[];
}
function getForcedLinuxWindowSystem(env: NodeJS.ProcessEnv): "wayland" | "x11" | null {
const ozonePlatform =
env.OZONE_PLATFORM?.toLowerCase() ??
env.ELECTRON_OZONE_PLATFORM_HINT?.toLowerCase() ??
null;
if (ozonePlatform === "wayland" || ozonePlatform === "x11") {
return ozonePlatform;
function normalizeLinuxWindowSystem(value: string | undefined): "wayland" | "x11" | null {
const normalized = value?.trim().toLowerCase();
if (normalized === "wayland" || normalized === "x11") {
return normalized;
}
return null;
}
function getForcedLinuxWindowSystem(env: NodeJS.ProcessEnv): "wayland" | "x11" | null {
return (
normalizeLinuxWindowSystem(env.OZONE_PLATFORM) ??
normalizeLinuxWindowSystem(env.ELECTRON_OZONE_PLATFORM_HINT)
);
}
export function shouldForceLinuxEgl(env: NodeJS.ProcessEnv): boolean {
const forcedWindowSystem = getForcedLinuxWindowSystem(env);
if (forcedWindowSystem === "wayland") {