From f06925cefbd2a799a7936872cd98e8cc43a89569 Mon Sep 17 00:00:00 2001 From: Yiannis Spanos <42875202+ispanos@users.noreply.github.com> Date: Sun, 14 Aug 2022 15:54:04 +0300 Subject: [PATCH 1/4] Update detect_desktop_environment() Use `XDG_CURRENT_DESKTOP` environmental variable Note that older methods of detecting the Desktop Environment are depreciated --- devices/linux/Files/main.py | 42 +++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/devices/linux/Files/main.py b/devices/linux/Files/main.py index 90db4a9af..2f6f41072 100644 --- a/devices/linux/Files/main.py +++ b/devices/linux/Files/main.py @@ -107,29 +107,31 @@ def detect_desktop_environment() -> str: """ Detect what desktop type is used. This method is prepared for possible future use with password encryption on supported distros - - the function below was partially copied from - https://ubuntuforums.org/showthread.php?t=1139057 """ - desktop_environment = 'generic' + if os.environ.get('XDG_CURRENT_DESKTOP'): + return os.environ.get('XDG_CURRENT_DESKTOP').lower() + + # Depreciated method for older distributions if os.environ.get('KDE_FULL_SESSION') == 'true': - desktop_environment = 'kde' - elif os.environ.get('GNOME_DESKTOP_SESSION_ID'): - desktop_environment = 'gnome' + return 'kde' + + if os.environ.get('GNOME_DESKTOP_SESSION_ID'): + return 'gnome' + + try: + shell_command = subprocess.Popen(['xprop', '-root', + '_DT_SAVE_MODE'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = shell_command.communicate() + info = out.decode('utf-8').strip() + except (OSError, RuntimeError): + pass else: - try: - shell_command = subprocess.Popen(['xprop', '-root', - '_DT_SAVE_MODE'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - out, _ = shell_command.communicate() - info = out.decode('utf-8').strip() - except (OSError, RuntimeError): - pass - else: - if ' = "xfce4"' in info: - desktop_environment = 'xfce' - return desktop_environment + if ' = "xfce4"' in info: + return 'xfce' + + return 'generic' def get_system() -> List: From 9339ace3a867259d6f2f9491143597d127b21f21 Mon Sep 17 00:00:00 2001 From: Yiannis Spanos <42875202+ispanos@users.noreply.github.com> Date: Sun, 14 Aug 2022 15:55:23 +0300 Subject: [PATCH 2/4] Add contributor --- devices/linux/Files/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/devices/linux/Files/main.py b/devices/linux/Files/main.py index 2f6f41072..cf57d5cba 100644 --- a/devices/linux/Files/main.py +++ b/devices/linux/Files/main.py @@ -27,6 +27,7 @@ Contributors: Steffen Klemer https://github.com/sklemer1 ikreb7 https://github.com/ikreb7 + Yiannis Spanos https://github.com/ispanos Many thanks for multiple code fixes, feature ideas, styling remarks much of the code provided by them in the form of pull requests has been incorporated into the final form of this script. From 35611e8c7747a62f7584ee85e41bd70785c5e6e0 Mon Sep 17 00:00:00 2001 From: Yiannis Spanos <42875202+ispanos@users.noreply.github.com> Date: Sun, 14 Aug 2022 17:30:13 +0300 Subject: [PATCH 3/4] Fix nested if statement --- devices/linux/Files/main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/devices/linux/Files/main.py b/devices/linux/Files/main.py index cf57d5cba..220f32dc1 100644 --- a/devices/linux/Files/main.py +++ b/devices/linux/Files/main.py @@ -128,9 +128,8 @@ def detect_desktop_environment() -> str: info = out.decode('utf-8').strip() except (OSError, RuntimeError): pass - else: - if ' = "xfce4"' in info: - return 'xfce' + if ' = "xfce4"' in info: + return 'xfce' return 'generic' From fa3a6d9266a03d80bd8ef4a5576cf870e2dd30f3 Mon Sep 17 00:00:00 2001 From: Yiannis Spanos <42875202+ispanos@users.noreply.github.com> Date: Tue, 16 Aug 2022 14:54:38 +0300 Subject: [PATCH 4/4] Remove name from unused variable --- devices/linux/Files/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devices/linux/Files/main.py b/devices/linux/Files/main.py index 220f32dc1..c11e7775b 100644 --- a/devices/linux/Files/main.py +++ b/devices/linux/Files/main.py @@ -124,7 +124,7 @@ def detect_desktop_environment() -> str: '_DT_SAVE_MODE'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = shell_command.communicate() + out, _ = shell_command.communicate() info = out.decode('utf-8').strip() except (OSError, RuntimeError): pass