From f65dba3625bda3d7c489863688eee340c2e2831f Mon Sep 17 00:00:00 2001 From: Adnan Hodzic Date: Sat, 19 Feb 2022 16:19:01 +0100 Subject: [PATCH] Improved power_helper snap package detection --- README.md | 2 +- auto_cpufreq/power_helper.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2e213809..3f30bc38 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ This can be done by running: `sudo python3 power_helper.py --gnome_power_disable After auto-cpufreq git repo has been cloned (`git clone https://github.com/AdnanHodzic/auto-cpufreq.git`), navagiate to directory where `power_helper.py` script resides by running: `cd auto-cpufreq/auto_cpufreq` -After this step, all necessary changes will still be made automatically. However, if you wish to perform additonal "manual" settings this can be done by following instrucitons explained in next step. +After this step, all necessary changes will still be made automatically. However, if you wish to perform additonal "manual" settings this can be done by following instructions explained in next step. ### 2: auto-cpufreq config file diff --git a/auto_cpufreq/power_helper.py b/auto_cpufreq/power_helper.py index 6f92b10f..a8894cac 100644 --- a/auto_cpufreq/power_helper.py +++ b/auto_cpufreq/power_helper.py @@ -33,6 +33,8 @@ def does_command_exists(cmd): bluetoothctl_exists = does_command_exists("bluetoothctl") tlp_stat_exists = does_command_exists("tlp-stat") powerprofilesctl_exists = does_command_exists("powerprofilesctl") +snap_check = os.system("snap list | grep auto-cpufreq >/dev/null 2>&1") + # detect if gnome power profile service is running if os.getenv("PKG_MARKER") != "SNAP": @@ -281,7 +283,8 @@ def gnome_power_svc_disable_ext(ctx, power_selection): if systemctl_exists: # 0 is active if gnome_power_status != 0: - if os.getenv("PKG_MARKER") == "SNAP": + # 0 is success (snap package is installed) + if snap_check == 0: print("Power Profiles Daemon is already disabled, re-enable by running:\n" "sudo python3 power_helper.py --gnome_power_enable\n" "\nfollowed by running:\n" @@ -296,7 +299,8 @@ def gnome_power_svc_disable_ext(ctx, power_selection): # set balanced profile if its running before disabling it if gnome_power_status == 0 and powerprofilesctl_exists: - if os.getenv("PKG_MARKER") == "SNAP": + # 0 is success (snap package is installed) + if snap_check == 0: print("Using profile: ", gnome_power_disable) call(["powerprofilesctl", "set", gnome_power_disable])