Repository: electron/electron
Pull request: feat: add support for ELECTRON_OZONE_PLATFORM_HINT env var

#### Description of Change

> [!NOTE]  
> This is a resubmit of #35614, since #35630 is still blocked on upstream/pending further discussion.

Add support for the `ELECTRON_OZONE_PLATFORM_HINT` environment variable in order to make it easier for users to enable Wayland support for **all** Electron apps without having to manually patch application `.desktop` files (or other similar workarounds #30897).

The accepted values are the same [as upstream](https://chromium-review.googlesource.com/c/chromium/src/+/3188974), with the special `auto` value being recommended for most users (especially for those switching between X11 and Wayland environments).

When *both* the `--ozone-platform-hint` command line flag and the `ELECTRON_OZONE_PLATFORM_HINT` environment variable are specified, the command line flag has higher priority.

Fixes #30897

#### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] PR description included and stakeholders cc'd (@ckerr @deepak1556 @zcbenz)
- [x] `npm test` passes
- [x] [PR release notes](https://github.com/electron/clerk/blob/master/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/master/README.md#examples).

#### Release Notes

Notes: Added support for `ELECTRON_OZONE_PLATFORM_HINT` environment variable on Linux.

Changed files:
filename: docs/api/environment-variables.md
patch: @@ -111,6 +111,16 @@ Options:
 * `kioclient5`
 * `kioclient`
 
+### `ELECTRON_OZONE_PLATFORM_HINT` _Linux_
+
+Selects the preferred platform backend used on Linux. The default one is `x11`. `auto` selects Wayland if possible, X11 otherwise.
+
+Options:
+
+* `auto`
+* `wayland`
+* `x11`
+
 ## Development Variables
 
 The following environment variables are intended primarily for development and

filename: shell/browser/electron_browser_main_parts_linux.cc
patch: @@ -15,6 +15,9 @@
 #include "shell/common/thread_restrictions.h"
 #endif
 
+constexpr base::StringPiece kElectronOzonePlatformHint(
+    "ELECTRON_OZONE_PLATFORM_HINT");
+
 #if BUILDFLAG(OZONE_PLATFORM_WAYLAND)
 
 constexpr char kPlatformWayland[] = "wayland";
@@ -115,17 +118,20 @@ std::string MaybeFixPlatformName(const std::string& ozone_platform_hint) {
 }  // namespace
 
 void ElectronBrowserMainParts::DetectOzonePlatform() {
+  auto const env = base::Environment::Create();
   auto* const command_line = base::CommandLine::ForCurrentProcess();
   if (!command_line->HasSwitch(switches::kOzonePlatform)) {
-    const auto ozone_platform_hint =
+    auto ozone_platform_hint =
         command_line->GetSwitchValueASCII(switches::kOzonePlatformHint);
+    if (ozone_platform_hint.empty()) {
+      env->GetVar(kElectronOzonePlatformHint, &ozone_platform_hint);
+    }
     if (!ozone_platform_hint.empty()) {
       command_line->AppendSwitchASCII(
           switches::kOzonePlatform, MaybeFixPlatformName(ozone_platform_hint));
     }
   }
 
-  auto env = base::Environment::Create();
   std::string desktop_startup_id;
   if (env->GetVar("DESKTOP_STARTUP_ID", &desktop_startup_id))
     command_line->AppendSwitchASCII("desktop-startup-id", desktop_startup_id);