From 8f2f03f1341a07aa4516e5bc57117f6b46d6f381 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Mon, 26 Aug 2024 20:51:33 +0200 Subject: [PATCH] fix strip error on CommandOutput and fix desktop env detect. linux --- custom_components/easy_computer_manager/computer/common.py | 4 ++-- custom_components/easy_computer_manager/const.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/custom_components/easy_computer_manager/computer/common.py b/custom_components/easy_computer_manager/computer/common.py index 258273b..27af9b8 100644 --- a/custom_components/easy_computer_manager/computer/common.py +++ b/custom_components/easy_computer_manager/computer/common.py @@ -11,8 +11,8 @@ class CommandOutput: def __init__(self, command: str, return_code: int, output: str, error: str) -> None: self.command = command self.return_code = return_code - self.output = output - self.error = error + self.output = output.strip() + self.error = error.strip() def successful(self) -> bool: return self.return_code == 0 diff --git a/custom_components/easy_computer_manager/const.py b/custom_components/easy_computer_manager/const.py index 008664d..f85ffe8 100644 --- a/custom_components/easy_computer_manager/const.py +++ b/custom_components/easy_computer_manager/const.py @@ -22,8 +22,7 @@ ACTIONS = { "linux": ["awk -F'=' '/^NAME=|^VERSION=/{gsub(/\"/, \"\", $2); printf $2\" \"}\' /etc/os-release && echo", "lsb_release -a | awk '/Description/ {print $2, $3, $4}'"] }, "desktop_environment": { - "linux": [ - "echo \"${XDG_CURRENT_DESKTOP:-${DESKTOP_SESSION:-$(basename $(grep -Eo \'exec .*(startx|xinitrc)\' ~/.xsession 2>/dev/null | awk \'{print $2}\'))}}\""], + "linux": ["for session in $(ls /usr/bin/*session 2>/dev/null); do basename $session | sed 's/-session//'; done | grep -E 'gnome|kde|xfce|mate|lxde|cinnamon|budgie|unity' | head -n 1"], "windows": ["echo Windows"] }, "shutdown": {