mirror of
https://github.com/AdnanHodzic/auto-cpufreq.git
synced 2025-07-28 08:04:25 +02:00
app no longer needs root to start, only asks when needed
This commit is contained in:
parent
3a4fd1dc3f
commit
3a8eaaf03e
@ -15,7 +15,7 @@ CSS_FILE = "/usr/local/share/auto-cpufreq/scripts/style.css"
|
||||
|
||||
HBOX_PADDING = 20
|
||||
|
||||
class MyWindow(Gtk.Window):
|
||||
class ToolWindow(Gtk.Window):
|
||||
def __init__(self):
|
||||
super().__init__(title="auto-cpufreq")
|
||||
self.set_default_size(600, 480)
|
||||
@ -80,8 +80,7 @@ class MyWindow(Gtk.Window):
|
||||
return True
|
||||
|
||||
|
||||
|
||||
win = MyWindow()
|
||||
win = ToolWindow()
|
||||
win.connect("destroy", Gtk.main_quit)
|
||||
win.show_all()
|
||||
GLib.set_application_name("auto-cpufreq")
|
||||
|
@ -9,11 +9,13 @@ import os
|
||||
import platform as pl
|
||||
|
||||
sys.path.append("../../")
|
||||
from subprocess import getoutput, call
|
||||
from subprocess import getoutput, run, PIPE
|
||||
from auto_cpufreq.core import sysinfo, distro_info, set_override, get_override, get_formatted_version, dist_name, deploy_daemon, remove_daemon
|
||||
|
||||
from io import StringIO
|
||||
|
||||
PKEXEC_ERROR = "Error executing command as another user: Not authorized\n\nThis incident has been reported.\n"
|
||||
|
||||
if os.getenv("PKG_MARKER") == "SNAP":
|
||||
auto_cpufreq_stats_path = "/var/snap/auto-cpufreq/current/auto-cpufreq.stats"
|
||||
else:
|
||||
@ -32,7 +34,7 @@ def get_version():
|
||||
return getoutput("echo \(Snap\) $SNAP_VERSION")
|
||||
# aur package
|
||||
elif dist_name in ["arch", "manjaro", "garuda"]:
|
||||
aur_pkg_check = call("pacman -Qs auto-cpufreq > /dev/null", shell=True)
|
||||
aur_pkg_check = run("pacman -Qs auto-cpufreq > /dev/null", shell=True)
|
||||
if aur_pkg_check == 1:
|
||||
return get_formatted_version()
|
||||
else:
|
||||
@ -77,7 +79,10 @@ class RadioButtonView(Gtk.Box):
|
||||
|
||||
def on_button_toggled(self, button, override):
|
||||
if button.get_active():
|
||||
set_override(override)
|
||||
result = run(f"pkexec auto-cpufreq --force={override}", shell=True, stdout=PIPE, stderr=PIPE)
|
||||
if result.stderr.decode() == PKEXEC_ERROR:
|
||||
self.set_selected()
|
||||
|
||||
|
||||
def set_selected(self):
|
||||
override = get_override()
|
||||
@ -170,7 +175,9 @@ class DropDownMenu(Gtk.MenuButton):
|
||||
confirm.destroy()
|
||||
if response == Gtk.ResponseType.YES:
|
||||
try:
|
||||
remove_daemon()
|
||||
result = run("pkexec auto-cpufreq --remove", shell=True, stdout=PIPE, stderr=PIPE)
|
||||
if result.stderr.decode() == PKEXEC_ERROR:
|
||||
raise Exception("Authorization was cancelled")
|
||||
dialog = Gtk.MessageDialog(
|
||||
transient_for=parent,
|
||||
message_type=Gtk.MessageType.INFO,
|
||||
@ -250,7 +257,9 @@ class DaemonNotRunningView(Gtk.Box):
|
||||
|
||||
def install_daemon(self, button, parent):
|
||||
try:
|
||||
deploy_daemon()
|
||||
result = run("pkexec auto-cpufreq --install", shell=True, stdout=PIPE, stderr=PIPE)
|
||||
if result.stderr.decode() == PKEXEC_ERROR:
|
||||
raise Exception("Authorization was cancelled")
|
||||
dialog = Gtk.MessageDialog(
|
||||
transient_for=parent,
|
||||
message_type=Gtk.MessageType.INFO,
|
||||
|
@ -12,8 +12,8 @@
|
||||
<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>
|
||||
<annotate key="org.freedesktop.policykit.exec.path">/opt/auto-cpufreq/venv/bin/auto-cpufreq</annotate>
|
||||
<!-- <annotate key="org.freedesktop.policykit.exec.argv1">/opt/auto-cpufreq/venv/bin/auto-cpufreq</annotate> -->
|
||||
<!-- <annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate> -->
|
||||
</action>
|
||||
</policyconfig>
|
@ -5,12 +5,14 @@ venv_dir=/opt/auto-cpufreq/venv
|
||||
. "${venv_dir}/bin/activate"
|
||||
python_command="${venv_dir}/bin/python ${venv_dir}/bin/app.py"
|
||||
|
||||
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
|
||||
# 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
|
||||
|
||||
${python_command}
|
Loading…
x
Reference in New Issue
Block a user