Skip to content

Commit b719cc2

Browse files
committed
Fixing ryzenadj error & Removing registry startup option.
1 parent 8ec66d8 commit b719cc2

File tree

3 files changed

+68
-67
lines changed

3 files changed

+68
-67
lines changed

G14Control.pyw

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,6 @@ def quit_app():
223223

224224
data.run_power_thread = False
225225
data.run_gaming_thread = False
226-
# if data.power_thread is not None and data.power_thread.is_alive():
227-
# data.power_thread.kill()
228-
# while data.power_thread.isAlive():
229-
# if data.config["debug"]:
230-
# print("Waiting for power thread to die...")
231-
# time.sleep(0.25)
232-
# print("Power thread was alive, and now is dead.")
233-
234-
# if data.gaming_thread is not None and data.gaming_thread.is_alive():
235-
# data.gaming_thread.kill()
236-
# while data.gaming_thread.isAlive():
237-
# if data.config["debug"]:
238-
# print("Waiting for gaming thread to die...")
239-
# time.sleep(0.25)
240-
# print("Gaming thread was alive, and now is dead.")
241226
if device is not None:
242227
device.close()
243228
try:
@@ -540,7 +525,7 @@ if __name__ == "__main__":
540525
# Initialize the icon app and set its name
541526
icon_app: Icon = pystray.Icon(config["app_name"])
542527
# If running as admin or in debug mode, launch program
543-
if is_admin() or config["debug"]:
528+
if is_admin():
544529
startup(config, icon_app)
545530
else: # Re-run the program with admin rights
546531
ctypes.windll.shell32.ShellExecuteW(

G14RunCommands.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,8 @@ def set_boost(self, state, notification=True):
9999
self.do_boost(state)
100100
if notification is True:
101101
self.notify("Boost ENABLED") # Inform the user
102-
elif state is False: # Deactivate boost
103-
self.do_boost(state)
104-
if notification is True:
105-
self.notify("Boost DISABLED") # Inform the user
106-
elif state == 0:
107-
self.do_boost(state)
102+
elif state is False or state == 0: # Deactivate boost
103+
self.do_boost(False)
108104
if notification is True:
109105
self.notify("Boost DISABLED") # Inform the user
110106
elif state == 4:
@@ -239,24 +235,39 @@ def set_atrofac(self, asus_plan, cpu_curve=None, gpu_curve=None):
239235
cmdargs = atrofac + " fan --gpu " + gpu_curve + " --plan " + asus_plan
240236
else:
241237
cmdargs = atrofac + " --plan " + asus_plan
242-
result = sp.check_output(cmdargs, shell=True, creationflags=sp.CREATE_NO_WINDOW)
243-
if self.config["debug"]:
244-
print(result)
238+
try:
239+
result = sp.check_output(
240+
cmdargs, shell=True, creationflags=sp.CREATE_NO_WINDOW
241+
)
242+
if self.config["debug"]:
243+
print(result)
244+
except Exception:
245+
if self.config["debug"]:
246+
print("Error setting fan speeds.")
245247

246-
def set_ryzenadj(self, tdp):
248+
def set_ryzenadj(self, tdp, attempts=3):
247249
config = self.config
248250
ryzenadj = str(os.path.join(config["temp_dir"] + "ryzenadj.exe"))
249251
if tdp is None:
250252
pass
251253
else:
252-
result = sp.check_output(
253-
ryzenadj + " -a " + str(tdp) + " -b " + str(tdp),
254-
shell=True,
255-
creationflags=sp.CREATE_NO_WINDOW,
256-
stderr=STDOUT,
257-
)
258-
if self.config["debug"]:
259-
print(result.decode("utf-8"))
254+
try:
255+
result = sp.check_output(
256+
ryzenadj + " -a " + str(tdp) + " -b " + str(tdp),
257+
shell=True,
258+
creationflags=sp.CREATE_NO_WINDOW,
259+
)
260+
if self.config["debug"]:
261+
print(result.decode("utf-8"))
262+
except Exception:
263+
print("There was an error applying ryzenadj\n Attempt #" + attempts)
264+
if attempts == 0:
265+
self.notify(
266+
"There was an error apply ryzenadj TDP power settings...\n"
267+
+ "This is relatively normal."
268+
)
269+
else:
270+
self.set_ryzenadj(tdp, attempts - 1)
260271

261272
def set_power_plan(self, GUID, do_notify=False):
262273
print("setting power plan GUID to: ", GUID)

G14Utils.py

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@
99
import subprocess as sp
1010

1111

12-
# Adds G14Control.exe to the windows registry to start on boot/login
13-
def registry_add(registry_key_loc, G14dir):
14-
G14exe = "G14Control.exe"
15-
G14dir = str(G14dir)
16-
G14fileloc = os.path.join(G14dir, G14exe)
17-
G14Key = winreg.OpenKey(
18-
winreg.HKEY_CURRENT_USER, registry_key_loc, 0, winreg.KEY_SET_VALUE
19-
)
20-
winreg.SetValueEx(G14Key, "G14Control", 1, winreg.REG_SZ, G14fileloc)
21-
22-
23-
# Removes G14Control.exe from the windows registry
24-
def registry_remove(registry_key_loc, G14dir):
25-
G14dir = str(G14dir)
26-
G14Key = winreg.OpenKey(
27-
winreg.HKEY_CURRENT_USER, registry_key_loc, 0, winreg.KEY_ALL_ACCESS
28-
)
29-
winreg.DeleteValue(G14Key, "G14Control")
12+
# # Adds G14Control.exe to the windows registry to start on boot/login
13+
# def registry_add(registry_key_loc, G14dir):
14+
# G14exe = "G14Control.exe"
15+
# G14dir = str(G14dir)
16+
# G14fileloc = os.path.join(G14dir, G14exe)
17+
# G14Key = winreg.OpenKey(
18+
# winreg.HKEY_CURRENT_USER, registry_key_loc, 0, winreg.KEY_SET_VALUE
19+
# )
20+
# winreg.SetValueEx(G14Key, "G14Control", 1, winreg.REG_SZ, G14fileloc)
21+
# winreg.CloseKey(G14Key)
22+
23+
24+
# # Removes G14Control.exe from the windows registry
25+
# def registry_remove(registry_key_loc, G14dir):
26+
# G14dir = str(G14dir)
27+
# G14Key = winreg.OpenKey(
28+
# winreg.HKEY_CURRENT_USER, registry_key_loc, 0, winreg.KEY_ALL_ACCESS
29+
# )
30+
# winreg.DeleteValue(G14Key, "G14Control")
31+
# winreg.CloseKey(G14Key)
3032

3133

3234
# Checks if G14Control registry entry exists already
@@ -70,20 +72,20 @@ def startup_checks(data):
7072
# Adds registry entry if enabled in config, but not when in debug mode.
7173
# if not registry entry is already existing,
7274
# removes registry entry if registry exists but setting is disabled:
73-
reg_run_enabled = registry_check(data.registry_key_loc, G14dir)
74-
75-
if (
76-
data.config["start_on_boot"]
77-
and not data.config["debug"]
78-
and not reg_run_enabled
79-
):
80-
registry_add(data.registry_key_loc, G14dir)
81-
if (
82-
not data.config["start_on_boot"]
83-
and not data.config["debug"]
84-
and reg_run_enabled
85-
):
86-
registry_remove(data.registry_key_loc, data.G14dir)
75+
# reg_run_enabled = registry_check(data.registry_key_loc, G14dir)
76+
77+
# if (
78+
# data.config["start_on_boot"]
79+
# and not data.config["debug"]
80+
# and not reg_run_enabled
81+
# ):
82+
# registry_add(data.registry_key_loc, G14dir)
83+
# if (
84+
# not data.config["start_on_boot"]
85+
# and not data.config["debug"]
86+
# and reg_run_enabled
87+
# ):
88+
# registry_remove(data.registry_key_loc, data.G14dir)
8789
return data.auto_power_switch
8890

8991

@@ -165,8 +167,10 @@ def get_windows_plan_map(windows_plans):
165167
def is_admin():
166168
try:
167169
# Returns true if the user launched the app as admin
170+
val = ctypes.windll.shell32.IsUserAnAdmin()
171+
print("is admin?:" + val)
168172
return ctypes.windll.shell32.IsUserAnAdmin()
169-
except OSError or WindowsError:
173+
except Exception:
170174
return False
171175

172176

@@ -179,6 +183,7 @@ def get_windows_theme():
179183
)
180184
# Taskbar (where icon is displayed) uses the 'System' light theme key. Index 0 is the value, index 1 is the type of key
181185
value = winreg.QueryValueEx(sub_key, "SystemUsesLightTheme")[0]
186+
sub_key.Close()
182187
return value # 1 for light theme, 0 for dark theme
183188

184189

0 commit comments

Comments
 (0)