From efc32118b6b079462255890a7cb7c2e09ae9d473 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 4 May 2022 21:50:32 +0200 Subject: feat: use wayland when available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Auto-detect wayland in the yarn watch script. We use a shell script wrapper to launch sophie with wayland-specific arguments whenever appropriate. Because of this, the electron binary that ships with sophie has been renamed to sophie-bin. Signed-off-by: Kristóf Marussy --- scripts/watch.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/watch.js b/scripts/watch.js index eeee6e4..5db0d30 100644 --- a/scripts/watch.js +++ b/scripts/watch.js @@ -1,4 +1,5 @@ import { spawn } from 'node:child_process'; +import os from 'node:os'; import path from 'node:path'; import { watch } from 'chokidar'; @@ -31,7 +32,7 @@ const userDataDir = path.join(thisDir, '../userDataDir/development'); /** @type {RegExp[]} */ const stderrIgnorePatterns = [ - // warning about devtools extension + // Warning about devtools extension // https://github.com/cawa-93/vite-electron-builder/issues/492 // https://github.com/MarshallOfSound/electron-devtools-installer/issues/143 /ExtensionLoadWarning/, @@ -44,6 +45,8 @@ const stderrIgnorePatterns = [ // Does not seem to occur in production // https://github.com/electron/electron/issues/32133#issuecomment-1079916988 /(sandbox_bundle\.js script failed to run|object null is not iterable).+ node:electron\/js2c\/sandbox_bundle \(160\)$/, + // Warning when GPU-accelerated video decoding is not available (some wayland configs) + /Passthrough is not supported, GL is/, ]; /** @@ -134,6 +137,20 @@ function setupMainPackageWatcher(viteDevServer) { const portOrDefault = port || 3000; process.env.VITE_DEV_SERVER_URL = `${protocol}//${hostOrDefault}:${portOrDefault}/`; + /** @type {string[]} */ + let extraArgs = []; + + if (['aix', 'freebsd', 'linux', 'openbsd', 'sunos'].includes(os.platform())) { + // Use wayland display server if available. + extraArgs = + 'WAYLAND_DISPLAY' in process.env + ? [ + '--enable-features=WaylandWindowDecorations,WebRTCPipeWireCapturer', + '--ozone-platform=wayland', + ] + : ['--ozone-platform=x11']; + } + /** @type {import('child_process').ChildProcessByStdio | undefined} */ let childProcess; @@ -144,7 +161,12 @@ function setupMainPackageWatcher(viteDevServer) { function spawnProcess() { childProcess = spawn( String(electronPath), - ['.', `--user-data-dir=${userDataDir}`, ...process.argv.slice(2)], + [ + '.', + `--user-data-dir=${userDataDir}`, + ...extraArgs, + ...process.argv.slice(2), + ], { stdio: ['inherit', 'inherit', 'pipe'], }, -- cgit v1.2.3-54-g00ecf