gh-85644: webbrowser: Use $XDG_CURRENT_DESKTOP to check desktop (GH-21731)

Usage of $GNOME_DESKTOP_SESSION_ID env variable is deprecated since
GNOME 3.30.0 [1], so should not be used, while the standard
XDG_CURRENT_DESKTOP should be instead preferred.

[1] https://gitlab.gnome.org/GNOME/gnome-session/-/commit/00e0e6226371d53f65
This commit is contained in:
Marco Trevisan 2024-03-02 13:48:24 +01:00 committed by GitHub
parent 5dc8c84d39
commit 140d9ec4bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -418,12 +418,18 @@ def register_X_browsers():
if shutil.which("gio"): if shutil.which("gio"):
register("gio", None, BackgroundBrowser(["gio", "open", "--", "%s"])) register("gio", None, BackgroundBrowser(["gio", "open", "--", "%s"]))
# Equivalent of gio open before 2015 xdg_desktop = os.getenv("XDG_CURRENT_DESKTOP", "").split(":")
if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gvfs-open"):
# The default GNOME3 browser
if (("GNOME" in xdg_desktop or
"GNOME_DESKTOP_SESSION_ID" in os.environ) and
shutil.which("gvfs-open")):
register("gvfs-open", None, BackgroundBrowser("gvfs-open")) register("gvfs-open", None, BackgroundBrowser("gvfs-open"))
# The default KDE browser # The default KDE browser
if "KDE_FULL_SESSION" in os.environ and shutil.which("kfmclient"): if (("KDE" in xdg_desktop or
"KDE_FULL_SESSION" in os.environ) and
shutil.which("kfmclient")):
register("kfmclient", Konqueror, Konqueror("kfmclient")) register("kfmclient", Konqueror, Konqueror("kfmclient"))
# Common symbolic link for the default X11 browser # Common symbolic link for the default X11 browser

View File

@ -0,0 +1,2 @@
Use the ``XDG_CURRENT_DESKTOP`` environment variable in :mod:`webbrowser` to check desktop.
Prefer it to the deprecated ``GNOME_DESKTOP_SESSION_ID`` for GNOME detection.