Skip to content

fix: set XDG_CURRENT_DESKTOP env var back to original value before invoking xdg utils - #45310

Merged
ckerr merged 8 commits into
electron:mainfrom
esimkowitz:fix-platform-util
Apr 25, 2025
Merged

ckerr merged 8 commits into
electron:mainfrom
esimkowitz:fix-platform-util

Conversation

@esimkowitz

@esimkowitz esimkowitz commented Jan 23, 2025 •

Copy link
Copy Markdown
Contributor

Description of Change

This PR corrects the XDG_CURRENT_DESKTOP environment variable, with the goal of ensuring that electron.shell.openExternal and electron.shell.openPath actually honor the user-defined system defaults on Linux.

Currently, this variable is overridden by Electron to Unity (the original value is preserved in the ORIGINAL_XDG_CURRENT_DESKTOP variable). This was introduced by #23512 to workaround #5050 and #9046, however it causes xdg-open and similar utilities which electron.shell relies on to no longer honor the system defaults if a user is running the GNOME desktop environment (I have only tested this on GNOME, but I assume this is valid for all non-Unity environments).

This change preserves the overridden environment variable value for use by Electron and Chromium. When a call needs to be made to the XDG utilities, the original value will be dynamically injected back into the environment variable set that is sent to the spawned XDG process.

cc @clavin @mlaurencin

fixes #45129

Checklist

Release Notes

Notes: Fixed electron.shell.openExternal and electron.shell.openPath to honor user-defined system defaults on Linux

@welcome

welcome Bot commented Jan 23, 2025

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

Semantic PR titles

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Commit signing

This repo enforces commit signatures for all incoming PRs.
To sign your commits, see GitHub's documentation on Telling Git about your signing key.

PR tips

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jan 23, 2025
@ckerr

ckerr commented Jan 23, 2025

Copy link
Copy Markdown
Member

some breadcrumbs: looks like the XDG_CURRENT_DESKTOP change was introduced by #23512 to workaround #5050 and #9046.

@esimkowitz would this PR make ORIGINAL_XDG_CURRENT_DESKTOP moot?

@esimkowitz

Copy link
Copy Markdown
Contributor Author

No, because I'm not actually updating the env var for the Electron process (at least I don't think I am), I'm just updating it when calling out to XDG for opening links/paths externally. If a new process is spawned via Node, it would need to set this variable itself using the ORIGINAL_XDG_CURRENT_DESKTOP value if it wants to preserve user settings. I assume that was the original intention of adding this variable.

@esimkowitz

esimkowitz commented Jan 23, 2025 •

Copy link
Copy Markdown
Contributor Author

It may make sense, though, if the updated XDG value is only being used for the app indicators, to limit its application to only system calls that update the app indicators. I wonder, too, if this is an outdated workaround. It may be worth auditing current desktop environment capabilities to see if this is still needed.

Update: It seems like the Chromium codebase handles this behavior, I don't have the domain knowledge to say whether this can be limited beyond the env var that Chromium picks up.

@esimkowitz

Copy link
Copy Markdown
Contributor Author

Looks like one of the builds failed, it seems like a transient error. @ckerr can you restart the failing job?

@esimkowitz esimkowitz changed the title fix: set XDG_CURRENT_DESKTOP env var back to original value before invoking xdg utils fix: set XDG_CURRENT_DESKTOP env var back to original value before invoking xdg utils Jan 23, 2025
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jan 30, 2025
@samuelmaddock samuelmaddock added semver/patch backwards-compatible bug fixes target/32-x-y PR should also be added to the "32-x-y" branch. target/33-x-y PR should also be added to the "33-x-y" branch. target/34-x-y PR should also be added to the "34-x-y" branch. target/35-x-y PR should also be added to the "35-x-y" branch. labels Jan 31, 2025
@esimkowitz

Copy link
Copy Markdown
Contributor Author

@samuelmaddock can you rerun the build for this? I believe the Windows ARM build failure was transient

@esimkowitz

Copy link
Copy Markdown
Contributor Author

@samuelmaddock @ckerr checking as this has been dormant for a month, can you rerun the checks for this? I believe they should all pass and the failures were transient.

@codebytere

Copy link
Copy Markdown
Member

@esimkowitz could you please rebase this?

@codebytere
codebytere requested a review from ckerr February 25, 2025 20:39

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix!

Comment thread shell/common/platform_util_linux.cc Resolved
@codebytere
codebytere requested a review from ckerr March 3, 2025 09:34
@github-actions github-actions Bot added the target/36-x-y PR should also be added to the "36-x-y" branch. label Mar 5, 2025
@esimkowitz

Copy link
Copy Markdown
Contributor Author

@ckerr I've rebased my PR to the latest main, can you re-review when you get a chance?

@esimkowitz

Copy link
Copy Markdown
Contributor Author

Hi @ckerr @codebytere, the backport checks are failing for this, it seems like it's triggering for an unchanged file, can you help me understand what's causing this? I'd like to get this merged soon as it's been open for 2 months and I keep having to rebase it...

@esimkowitz

Copy link
Copy Markdown
Contributor Author

Hi @ckerr @codebytere can you help me understand what is blocking this? This PR is getting pretty old and I would like to get this checked in...

@clavin clavin left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Requesting one small change 😄

With the original issues about Pantheon for reference, I also took the time to go through all the uses of the XDG_CURRENT_DESKTOP env var in Chromium. I only found one bit of code that could have different behavior, but we don't use that Chromium code. So, I believe this change to be reasonably safe.

As a separate follow-up to this PR we should look at removing the XDG_CURRENT_DESKTOP workaround entirely imo.

P.S. Sorry about the long tail on landing this change! I'll keep my eye on this one.

Comment thread shell/common/platform_util_linux.cc Resolved
@trop

trop Bot commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "33-x-y", please check out #46787

@trop

trop Bot commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "36-x-y", please check out #46788

@trop trop Bot added in-flight/36-x-y and removed target/33-x-y PR should also be added to the "33-x-y" branch. labels Apr 25, 2025
@trop

trop Bot commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "35-x-y", please check out #46789

@trop trop Bot removed the target/36-x-y PR should also be added to the "36-x-y" branch. label Apr 25, 2025
@trop

This comment was marked as outdated.

@trop

trop Bot commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "34-x-y", please check out #46791

@trop trop Bot added in-flight/35-x-y in-flight/32-x-y in-flight/34-x-y and removed target/35-x-y PR should also be added to the "35-x-y" branch. target/32-x-y PR should also be added to the "32-x-y" branch. target/34-x-y PR should also be added to the "34-x-y" branch. in-flight/32-x-y labels Apr 25, 2025
ckerr pushed a commit that referenced this pull request Apr 25, 2025
…invoking xdg utils (#46787)

fix: set `XDG_CURRENT_DESKTOP` env var back to original value before invoking xdg utils (#45310)

* Fix XDG_CURRENT_DESKTOP before invoking XDGUtil

* apply suggestion

* use existing XDG_CURRENT_DESKTOP const

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Evan Simkowitz <[email protected]>
@trop trop Bot added merged/33-x-y PR was merged to the "33-x-y" branch. and removed in-flight/33-x-y labels Apr 25, 2025
ckerr pushed a commit that referenced this pull request Apr 25, 2025
…invoking xdg utils (#46791)

fix: set `XDG_CURRENT_DESKTOP` env var back to original value before invoking xdg utils (#45310)

* Fix XDG_CURRENT_DESKTOP before invoking XDGUtil

* apply suggestion

* use existing XDG_CURRENT_DESKTOP const

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Evan Simkowitz <[email protected]>
@trop trop Bot added merged/34-x-y PR was merged to the "34-x-y" branch. and removed in-flight/34-x-y labels Apr 25, 2025
ckerr pushed a commit that referenced this pull request Apr 25, 2025
…invoking xdg utils (#46789)

fix: set `XDG_CURRENT_DESKTOP` env var back to original value before invoking xdg utils (#45310)

* Fix XDG_CURRENT_DESKTOP before invoking XDGUtil

* apply suggestion

* use existing XDG_CURRENT_DESKTOP const

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Evan Simkowitz <[email protected]>
@trop trop Bot added merged/35-x-y PR was merged to the "35-x-y" branch. and removed in-flight/35-x-y labels Apr 25, 2025
ckerr pushed a commit that referenced this pull request Apr 25, 2025
…invoking xdg utils (#46788)

fix: set `XDG_CURRENT_DESKTOP` env var back to original value before invoking xdg utils (#45310)

* Fix XDG_CURRENT_DESKTOP before invoking XDGUtil

* apply suggestion

* use existing XDG_CURRENT_DESKTOP const

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Evan Simkowitz <[email protected]>
@trop trop Bot added merged/36-x-y PR was merged to the "36-x-y" branch. and removed in-flight/36-x-y labels Apr 25, 2025
kigh-ota pushed a commit to kigh-ota/electron that referenced this pull request Sep 30, 2025
…invoking xdg utils (electron#45310)

* Fix XDG_CURRENT_DESKTOP before invoking XDGUtil

* apply suggestion

* use existing XDG_CURRENT_DESKTOP const
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/33-x-y PR was merged to the "33-x-y" branch. merged/34-x-y PR was merged to the "34-x-y" branch. merged/35-x-y PR was merged to the "35-x-y" branch. merged/36-x-y PR was merged to the "36-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong web browser opened when clicking links

5 participants