Skip to content

Commit 13f43fa

Browse files
committed
add pkexec policy and change wrapper for gui
1 parent 4ddbb9c commit 13f43fa

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

auto-cpufreq-installer

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function install {
6565
cp -r scripts/ /usr/local/share/auto-cpufreq/
6666
cp -r images/ /usr/local/share/auto-cpufreq/
6767
cp images/icon.png /usr/share/pixmaps/auto-cpufreq.png
68+
cp scripts/org.auto-cpufreq.pkexec.policy /usr/share/polkit-1/actions
6869

6970
# this is necessary since we need this script before we can run auto-cpufreq itself
7071
cp scripts/auto-cpufreq-venv-wrapper /usr/local/bin/auto-cpufreq

auto_cpufreq/core.py

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
warnings.filterwarnings("ignore")
2929

30+
# add path to auto-cpufreq executables for GUI
31+
os.environ["PATH"] += ":/usr/local/bin"
32+
3033
# ToDo:
3134
# - replace get system/CPU load from: psutil.getloadavg() | available in 5.6.2)
3235

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE policyconfig PUBLIC
3+
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
4+
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
5+
<policyconfig>
6+
<action id="org.auto-cpufreq.pkexec">
7+
<description>Run auto-cpufreq command</description>
8+
<message>Authentication is required to run auto-cpufreq</message>
9+
<icon_name>auto-cpufreq</icon_name>
10+
<defaults>
11+
<allow_any>auth_admin</allow_any>
12+
<allow_inactive>auth_admin</allow_inactive>
13+
<allow_active>auth_admin</allow_active>
14+
</defaults>
15+
<annotate key="org.freedesktop.policykit.exec.path">/opt/auto-cpufreq/venv/bin/python</annotate>
16+
<annotate key="org.freedesktop.policykit.exec.argv1">/opt/auto-cpufreq/venv/bin/app.py</annotate>
17+
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
18+
</action>
19+
</policyconfig>

scripts/start_app

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ venv_dir=/opt/auto-cpufreq/venv
55
. "${venv_dir}/bin/activate"
66
python_command="${venv_dir}/bin/python ${venv_dir}/bin/app.py"
77

8-
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}
8+
if [ "$XDG_SESSION_TYPE" = "wayland" ] ; then
9+
# necessary for running on wayland
10+
xhost +SI:localuser:root
11+
pkexec ${python_command}
12+
xhost -SI:localuser:root
13+
xhost
14+
else
15+
pkexec ${python_command}
16+
fi

0 commit comments

Comments
 (0)