Skip to content

Apply --ozone-platform from electron-flags.conf at startup on Linux - #18697

Merged
gtritchie merged 14 commits into
rstudio:mainfrom
victorwon2001:fix/issue-16594
Oct 2, 2026
Merged

gtritchie merged 14 commits into
rstudio:mainfrom
victorwon2001:fix/issue-16594

Conversation

@victorwon2001

@victorwon2001 victorwon2001 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Addresses #16594.

On Linux, Chromium picks its Ozone backend before main.ts runs, so an --ozone-platform from electron-flags.conf reached only the child processes. RStudio could then open with a blank window.

Approach

On packaged Linux builds, startup checks for a requested --ozone-platform before anything else starts (R detection, the login-shell query, startup timing). If the request differs from the backend Chromium started with, RStudio relaunches once with the switch placed ahead of the original arguments.

  • Precedence: an explicit --ozone-platform (or -ozone-platform) on the command line wins, then RSTUDIO_CHROMIUM_ARGUMENTS, then electron-flags.conf. After startup, neither the env var nor the conf file re-applies the switch in any spelling app.commandLine.appendSwitch accepts, so child processes match the browser process.
  • Only x11 and wayland are accepted. Other values are ignored and logged as warnings, and the relaunch decision is printed to the console.
  • There's no relaunch for --help, --version, --version-json, or --run-diagnostics, whose output would go to /dev/null in the relaunched process. There's also none in development builds, where exiting stops electron-forge's dev server.
  • If electron-flags.conf can't be read, the existing startup error dialog reports its path.

The relaunch decision is a pure function, planOzoneRelaunch in electron-flags.ts, so its cases are unit-tested.

Automated Tests

  • electron-flags.test.ts: conf parsing and loading (including an unreadable file), and the relaunch cases: matching, differing, and absent backends; env over conf; command line wins; switch spellings; arguments around --; unsupported values; dev builds; no second relaunch.
  • utils.test.ts: augmentCommandLineArguments leaves --ozone-platform unchanged.

npm run typecheck, npm run lint, and npm test pass on macOS. Lint reports no errors and two warnings already on main, in session-launcher.test.ts.

QA Notes

Not yet verified on Linux. With --ozone-platform=wayland in ~/.config/rstudio/electron-flags.conf:

  • In a Wayland session, the complete IDE opens under Wayland, and project/file arguments are preserved.
  • In an X11 session, rstudio --ozone-platform=x11 stays on X11.
  • rstudio --version prints the version and exits without relaunching.
  • With --ozone-platform=bogus instead, RStudio starts on its default backend and rdesktop.log has the warning.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards (no UI changes)
  • A reviewer is assigned to this PR
  • This PR passes all local unit tests

@gtritchie

Copy link
Copy Markdown
Member

Thanks for the PR, we'll take a look at it as soon as we can.

If you haven't already, please fill out and submit the contributor agreement: https://github.com/rstudio/rstudio/blob/main/CONTRIBUTING.md#contributing-code.

@victorwon2001

Copy link
Copy Markdown
Contributor Author

Replaced the unnecessary optional chaining in electron-flags.test.ts. Syntax, focused helper assertions, and whitespace checks passed; lint and the Electron test were unavailable because project-local tools are missing.

@kevinushey

Copy link
Copy Markdown
Collaborator

@victorwon2001 can you confirm if you've sent a signed CLA over?

@victorwon2001

Copy link
Copy Markdown
Contributor Author

Thanks for checking, @kevinushey. I've just emailed my signed individual CLA to [email protected].

@kevinushey

Copy link
Copy Markdown
Collaborator

Perfect, thanks! I can confirm we've received it; I'll do one more review.

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on -- the diagnosis (Ozone is selected in ElectronBrowserMainParts::PreEarlyInitialization, before the main script can appendSwitch, so only the real argv can influence it) is right, and a one-time relaunch is a reasonable way to get the configured value onto argv.

Review outcome: 4 correctness issues that I think should be addressed before merge (--version/--help now relaunch instead of printing; dev-mode relaunch tears down the forge dev server; an unusable configured value becomes a silent exit 0; conf silently overrides an explicit CLI switch and RSTUDIO_CHROMIUM_ARGUMENTS is not consulted), plus a NEWS placement fix and a few simplifications. Details inline.

Two notes on the PR description:

  • typecheck, lint, and the unit tests are listed as blocked, but I ran all three on a scratch worktree of this PR's head (04b0075): npm run typecheck and npm run lint are clean, and the new spec passes 8/8 under electron-mocha. So the description and checklist can be updated.
  • The NEWS entry landed in version/news/os/NEWS-2026.09.0-autumn-hawkbit.md, but this PR targets main (2026.10 / Blue Mistflower), whose notes now live in the root NEWS.md. Please move the entry there (### Fixed).

Comment thread src/node/desktop/src/main/main.ts Outdated
Comment thread src/node/desktop/src/main/main.ts Outdated
Comment thread src/node/desktop/src/main/main.ts Outdated
Comment thread src/node/desktop/src/main/main.ts Outdated
Comment thread version/news/os/NEWS-2026.09.0-autumn-hawkbit.md Outdated
Comment thread src/node/desktop/src/main/main.ts Outdated
Comment thread src/node/desktop/src/main/electron-flags.ts Outdated
Comment thread src/node/desktop/src/main/main.ts Outdated
Comment thread src/node/desktop/src/main/main.ts Outdated
@gtritchie

gtritchie commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Hi, I'm going to make the suggested fixes and push them to your branch, and see if I can get this PR merged today.

- Skip the relaunch for --help, --version, and --version-json, and in
  development builds, where exiting stops electron-forge's dev server
- Ignore and log values other than x11/wayland, trim trailing
  whitespace from electron-flags.conf lines, and log the relaunch
- Give --ozone-platform on the command line precedence over
  RSTUDIO_CHROMIUM_ARGUMENTS, and that over electron-flags.conf; neither
  re-applies the switch after startup, so child processes match
- Decide before R detection and the login-shell query start, and name
  the file when electron-flags.conf cannot be read
- Read the current backend from app.commandLine and append the switch
  instead of preserving its argv position

Addresses rstudio#16594
- Resolve the config directories inside the error handler, so an
  appData lookup failure reaches the startup error dialog
- Honor a final bare --ozone-platform in RSTUDIO_CHROMIUM_ARGUMENTS
  and report it as unsupported instead of using an earlier value
- Compare the Ozone switch to its initial state in the utils test,
  since Electron sets it on Linux

Addresses rstudio#16594
Chromium stops parsing switches at '--', so appending the switch after
an argument list like '-- script.R' left it as a plain argument and the
relaunched process kept the old backend. Only packaged builds relaunch,
and they make no assumption about argv[1].

Addresses rstudio#16594
Chromium treats everything after '--' as a plain argument, so such an
argument should not count as the user choosing a backend and suppress
the relaunch.

Addresses rstudio#16594
@gtritchie gtritchie changed the title Fix #16594: --ozone-platform=wayland works in command line but not elect Apply --ozone-platform from electron-flags.conf at startup on Linux Oct 2, 2026

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two startup issues need correction: diagnostics loses its terminal output during relaunch, and accepted alternate Ozone switch spellings can restore the browser/child backend mismatch.

Validation: typecheck and lint passed, with two existing lint warnings. The two changed test files had 37 passing tests and one failure because the review worktree lacks an rsession binary. Linux GUI startup remains unverified.

Comment thread src/node/desktop/src/main/main.ts Outdated
Comment thread src/node/desktop/src/main/electron-flags.ts Outdated
Chromium reads '-ozone-platform' in argv as well as '--ozone-platform',
and app.commandLine.appendSwitch, used for RSTUDIO_CHROMIUM_ARGUMENTS and
electron-flags.conf, also drops the prefix and lowercases the name. The
matchers knew only '--ozone-platform', so '-ozone-platform=x11' or
'--OZONE-PLATFORM=x11' could relaunch into one backend and then switch
the child processes to another.

Addresses rstudio#16594
Electron's Linux relauncher sends the new process's stdout and stderr to
/dev/null, which is where diagnostics reports its progress, its errors,
and the rsession output. Diagnostics shows no window, so it does not
need the configured backend.

Addresses rstudio#16594
@gtritchie
gtritchie merged commit 69f003e into rstudio:main Oct 2, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants