Use wayland if possible on linux
All checks were successful
Queue Release Build / prepare (push) Successful in 58s
Deploy Web Apps / deploy (push) Successful in 22m58s
Queue Release Build / build-linux (push) Successful in 1h10m11s
Queue Release Build / build-windows (push) Successful in 32m8s
Queue Release Build / finalize (push) Successful in 3m11s

This commit is contained in:
2026-03-13 20:13:05 +01:00
parent 00adf39121
commit 150c45c31a
7 changed files with 177 additions and 14 deletions

70
tools/launch-electron.js Normal file
View File

@@ -0,0 +1,70 @@
const { spawn } = require('child_process');
function isWaylandSession(env) {
const sessionType = String(env.XDG_SESSION_TYPE || '').trim().toLowerCase();
if (sessionType === 'wayland') {
return true;
}
return String(env.WAYLAND_DISPLAY || '').trim().length > 0;
}
function hasSwitch(args, switchName) {
const normalizedSwitch = `--${switchName}`;
return args.some((arg) => arg === normalizedSwitch || arg.startsWith(`${normalizedSwitch}=`));
}
function resolveElectronBinary() {
const electronModule = require('electron');
if (typeof electronModule === 'string') {
return electronModule;
}
if (electronModule && typeof electronModule.default === 'string') {
return electronModule.default;
}
throw new Error('Could not resolve the Electron executable.');
}
function buildElectronArgs(argv) {
const args = [...argv];
if (
process.platform === 'linux'
&& isWaylandSession(process.env)
&& !hasSwitch(args, 'ozone-platform')
) {
args.push('--ozone-platform=wayland');
}
return args;
}
function main() {
const electronBinary = resolveElectronBinary();
const args = buildElectronArgs(process.argv.slice(2));
const child = spawn(electronBinary, args, {
env: process.env,
stdio: 'inherit'
});
child.on('error', (error) => {
console.error(error instanceof Error ? error.message : String(error));
process.exit(1);
});
child.on('exit', (code, signal) => {
if (signal) {
process.kill(process.pid, signal);
return;
}
process.exit(code ?? 0);
});
}
main();