From a66f477af6f527d3aef3a153aa394ba56e20bce4 Mon Sep 17 00:00:00 2001 From: Oro <93224879+orowith2os@users.noreply.github.com> Date: Tue, 24 Jan 2023 03:29:57 -0600 Subject: [PATCH] Redo the Wayland checks for Linux (#327) * Redo the Wayland checks for Linux * Update the Wayland window decorations comments * Nit: don't nest if checks, update some comments * Nit: stricter env var checks * toLowerCase() on Wayland/Linux string checks * Use toLowerCase() properly Co-authored-by: Ven * Don't use toLowerCase() on XDG_SESSION_TYPE * Null safety for XDG_SESSION_TYPE and toLowerCase Co-authored-by: Ven --- src/main.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1ca5e01..855eaf7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,21 +25,22 @@ if (!app.requestSingleInstanceLock()) { } else { // Your data now belongs to CCP crashReporter.start({uploadToServer: false}); - if (process.env.USE_WAYLAND == "0") { - console.log("Wayland patches disabled."); - } else { - if (process.platform == "linux") { - if (process.env.XDG_SESSION_TYPE == "wayland") { - console.log("Wayland specific patches applied."); - app.commandLine.appendSwitch("ozone-platform=wayland"); - if (process.env.XDG_CURRENT_DESKTOP == "GNOME") { - app.commandLine.appendSwitch("enable-features=UseOzonePlatform,WaylandWindowDecorations"); - } else { - app.commandLine.appendSwitch("enable-features=UseOzonePlatform"); - } - } + // We use toLowerCase to account for desktops where XDG_SESSION_TYPE might be Wayland and not wayland. + if (process.platform.toLowerCase() === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") { + // Just using the native Wayland backend doesn't enable PipeWire capture, we need to enable it explicitly. + app.commandLine.appendSwitch('enable-features', 'WebRTCPipeWireCapturer'); + console.log("Wayland detected, using PipeWire for video capture."); + // Some people might want to disable the Wayland backend for one reason or another, such as for Wayland-specific bugs. + if (process.env.USE_WAYLAND === "0") { + console.log("Wayland backend disabled."); + } else { + console.log("Using native Wayland, not Xwayland. Disable with USE_WAYLAND=0 if you find issues."); + app.commandLine.appendSwitch('ozone-platform', 'wayland'); + // The Wayland spec doesn't require SSDs, so lets enable self-drawn window decorations. + // If SSDs are supported on the compositor, Electron will let the compositor handle the decorations. + app.commandLine.appendSwitch('enable-features', 'UseOzonePlatform,WaylandWindowDecorations'); + } } - } checkForDataFolder(); checkIfConfigExists();