Skip to content

Commit

Permalink
add pkexec policy and change wrapper for gui
Browse files Browse the repository at this point in the history
  • Loading branch information
shadeyg56 committed Feb 12, 2023
1 parent 4ddbb9c commit 13f43fa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions auto-cpufreq-installer
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function install {
cp -r scripts/ /usr/local/share/auto-cpufreq/
cp -r images/ /usr/local/share/auto-cpufreq/
cp images/icon.png /usr/share/pixmaps/auto-cpufreq.png
cp scripts/org.auto-cpufreq.pkexec.policy /usr/share/polkit-1/actions

# this is necessary since we need this script before we can run auto-cpufreq itself
cp scripts/auto-cpufreq-venv-wrapper /usr/local/bin/auto-cpufreq
Expand Down
3 changes: 3 additions & 0 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

warnings.filterwarnings("ignore")

# add path to auto-cpufreq executables for GUI
os.environ["PATH"] += ":/usr/local/bin"

# ToDo:
# - replace get system/CPU load from: psutil.getloadavg() | available in 5.6.2)

Expand Down
19 changes: 19 additions & 0 deletions scripts/org.auto-cpufreq.pkexec.policy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<action id="org.auto-cpufreq.pkexec">
<description>Run auto-cpufreq command</description>
<message>Authentication is required to run auto-cpufreq</message>
<icon_name>auto-cpufreq</icon_name>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_admin</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/opt/auto-cpufreq/venv/bin/python</annotate>
<annotate key="org.freedesktop.policykit.exec.argv1">/opt/auto-cpufreq/venv/bin/app.py</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
</policyconfig>
10 changes: 9 additions & 1 deletion scripts/start_app
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ venv_dir=/opt/auto-cpufreq/venv
. "${venv_dir}/bin/activate"
python_command="${venv_dir}/bin/python ${venv_dir}/bin/app.py"

pkexec env DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XDG_SESSION_TYPE=$XDG_SESSION_TYPE XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XAUTHORITY=$XAUTHORITY GTK_THEME=$GTK_THEME PATH=$PATH ${python_command}
if [ "$XDG_SESSION_TYPE" = "wayland" ] ; then
# necessary for running on wayland
xhost +SI:localuser:root
pkexec ${python_command}
xhost -SI:localuser:root
xhost
else
pkexec ${python_command}
fi

0 comments on commit 13f43fa

Please sign in to comment.