diff --git a/devices/linux/Files/main.py b/devices/linux/Files/main.py index 90db4a9af..c11e7775b 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. @@ -107,29 +108,30 @@ 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' - 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 + 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, _ = shell_command.communicate() + info = out.decode('utf-8').strip() + except (OSError, RuntimeError): + pass + if ' = "xfce4"' in info: + return 'xfce' + + return 'generic' def get_system() -> List: