9
9
import platform as pl
10
10
11
11
sys .path .append ("../../" )
12
- from subprocess import getoutput , call
12
+ from subprocess import getoutput , run , PIPE
13
13
from auto_cpufreq .core import sysinfo , distro_info , set_override , get_override , get_formatted_version , dist_name , deploy_daemon , remove_daemon
14
14
15
15
from io import StringIO
16
16
17
+ PKEXEC_ERROR = "Error executing command as another user: Not authorized\n \n This incident has been reported.\n "
18
+
17
19
if os .getenv ("PKG_MARKER" ) == "SNAP" :
18
20
auto_cpufreq_stats_path = "/var/snap/auto-cpufreq/current/auto-cpufreq.stats"
19
21
else :
@@ -32,7 +34,7 @@ def get_version():
32
34
return getoutput ("echo \(Snap\) $SNAP_VERSION" )
33
35
# aur package
34
36
elif dist_name in ["arch" , "manjaro" , "garuda" ]:
35
- aur_pkg_check = call ("pacman -Qs auto-cpufreq > /dev/null" , shell = True )
37
+ aur_pkg_check = run ("pacman -Qs auto-cpufreq > /dev/null" , shell = True )
36
38
if aur_pkg_check == 1 :
37
39
return get_formatted_version ()
38
40
else :
@@ -77,7 +79,10 @@ def __init__(self):
77
79
78
80
def on_button_toggled (self , button , override ):
79
81
if button .get_active ():
80
- set_override (override )
82
+ result = run (f"pkexec auto-cpufreq --force={ override } " , shell = True , stdout = PIPE , stderr = PIPE )
83
+ if result .stderr .decode () == PKEXEC_ERROR :
84
+ self .set_selected ()
85
+
81
86
82
87
def set_selected (self ):
83
88
override = get_override ()
@@ -170,7 +175,9 @@ def _remove_daemon(self, MenuItem, parent):
170
175
confirm .destroy ()
171
176
if response == Gtk .ResponseType .YES :
172
177
try :
173
- remove_daemon ()
178
+ result = run ("pkexec auto-cpufreq --remove" , shell = True , stdout = PIPE , stderr = PIPE )
179
+ if result .stderr .decode () == PKEXEC_ERROR :
180
+ raise Exception ("Authorization was cancelled" )
174
181
dialog = Gtk .MessageDialog (
175
182
transient_for = parent ,
176
183
message_type = Gtk .MessageType .INFO ,
@@ -250,7 +257,9 @@ def __init__(self, parent):
250
257
251
258
def install_daemon (self , button , parent ):
252
259
try :
253
- deploy_daemon ()
260
+ result = run ("pkexec auto-cpufreq --install" , shell = True , stdout = PIPE , stderr = PIPE )
261
+ if result .stderr .decode () == PKEXEC_ERROR :
262
+ raise Exception ("Authorization was cancelled" )
254
263
dialog = Gtk .MessageDialog (
255
264
transient_for = parent ,
256
265
message_type = Gtk .MessageType .INFO ,
0 commit comments