Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor detect_desktop_environment() #246

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions devices/linux/Files/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down