Skip to content

Commit 68fec01

Browse files
committed
Removing unnecessary files/ set power thread daemon/ Fix dgpu on&off/ power switch config option/ boost fix/ remove asus plan options from atrofac/ more debug print statments
1 parent b5b4931 commit 68fec01

File tree

16 files changed

+121
-207
lines changed

16 files changed

+121
-207
lines changed

.idea/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.idea/G14Control.iml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

G14Control.pyw

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ from pywinusb import hid
1818
from G14RunCommands import RunCommands
1919
from win10toast import ToastNotifier
2020

21-
import pickle
22-
from io import FileIO
21+
# import pickle
22+
# from io import FileIO
2323

2424
toaster = ToastNotifier()
2525

@@ -76,6 +76,12 @@ def get_active_plan_map():
7676
return active_plan_map
7777

7878

79+
def get_windows_plan_map():
80+
global windows_plans, windows_plan_map
81+
windows_plan_map = {x[1]: x[0] for x in windows_plans}
82+
return windows_plan_map
83+
84+
7985
def get_app_path():
8086
global G14dir
8187
G14Dir = ""
@@ -159,7 +165,7 @@ def deactivate_powerswitching(should_notify=True):
159165
class power_check_thread(threading.Thread):
160166

161167
def __init__(self):
162-
threading.Thread.__init__(self)
168+
threading.Thread.__init__(self, daemon=True)
163169

164170
def run(self):
165171
global auto_power_switch, ac, current_plan, default_ac_plan, default_dc_plan, config
@@ -198,38 +204,40 @@ class gaming_thread_impl(threading.Thread):
198204

199205
def __init__(self, name):
200206
self.name = name
201-
threading.Thread.__init__(self)
207+
threading.Thread.__init__(self, daemon=True)
202208

203209
def run(self): # Checks if user specified games/programs are running, and sw`itches to user defined plan, then switches back once closed
204-
global default_gaming_plan_games
210+
global default_gaming_plan_games, run_gaming_thread
205211
previous_plan = None # Define the previous plan to switch back to
206-
207-
while True: # Continuously check every 10 seconds
208-
output = os.popen('wmic process get description, processid').read()
209-
process = output.split("\n")
210-
processes = set(i.split(" ")[0] for i in process)
211-
# List of user defined processes
212-
targets = set(default_gaming_plan_games)
213-
if processes & targets: # Compare 2 lists, if ANY overlap, set game_running to true
214-
game_running = True
215-
else:
216-
game_running = False
217-
# If game is running and not on the desired gaming plan, switch to that plan
218-
if game_running and current_plan != default_gaming_plan:
219-
previous_plan = current_plan
220-
for plan in config['plans']:
221-
if plan['name'] == default_gaming_plan:
222-
apply_plan(plan)
223-
notify(plan['name'])
224-
break
225-
# If game is no longer running, and not on previous plan already (if set), then switch back to previous plan
226-
if not game_running and previous_plan is not None and previous_plan != current_plan:
227-
for plan in config['plans']:
228-
if plan['name'] == previous_plan:
229-
apply_plan(plan)
230-
break
231-
# Check for programs every 10 sec
232-
time.sleep(config['check_power_every'])
212+
if auto_power_switch:
213+
while run_gaming_thread: # Continuously check every 10 seconds
214+
output = os.popen(
215+
'wmic process get description, processid').read()
216+
process = output.split("\n")
217+
processes = set(i.split(" ")[0] for i in process)
218+
# List of user defined processes
219+
targets = set(default_gaming_plan_games)
220+
if processes & targets: # Compare 2 lists, if ANY overlap, set game_running to true
221+
game_running = True
222+
else:
223+
game_running = False
224+
# If game is running and not on the desired gaming plan, switch to that plan
225+
if game_running and current_plan != default_gaming_plan:
226+
previous_plan = current_plan
227+
for plan in config['plans']:
228+
if plan['name'] == default_gaming_plan:
229+
apply_plan(plan)
230+
notify(plan['name'])
231+
break
232+
# If game is no longer running, and not on previous plan already (if set), then switch back to previous plan
233+
if not game_running and previous_plan is not None and previous_plan != current_plan:
234+
for plan in config['plans']:
235+
if plan['name'] == previous_plan:
236+
apply_plan(plan)
237+
notify(plan['name'])
238+
break
239+
# Check for programs every 10 sec
240+
time.sleep(config['check_power_every'])
233241

234242
def raise_exception(self):
235243
thread_id = self.ident
@@ -293,9 +301,9 @@ def apply_plan(plan):
293301
def quit_app():
294302
global device, run_power_thread, run_gaming_thread, power_thread, gaming_thread
295303
# This will destroy the the tray icon gracefully.
296-
with FileIO('./config.DAT', mode='w') as fileio:
297-
pickle.dump(config, fileio)
298-
fileio.close()
304+
# with FileIO('./config.DAT', mode='w') as fileio:
305+
# pickle.dump(config, fileio)
306+
# fileio.close()
299307

300308
run_power_thread = False
301309
run_gaming_thread = False
@@ -310,9 +318,9 @@ def quit_app():
310318
device.close()
311319
try:
312320
icon_app.stop()
313-
sys.exit()
314321
except SystemExit:
315322
print('System Exit')
323+
sys.exit()
316324

317325

318326
def apply_plan_deactivate_switching(plan):
@@ -323,8 +331,9 @@ def apply_plan_deactivate_switching(plan):
323331

324332

325333
def set_windows_plan(plan):
326-
global active_plan_map, current_windows_plan, windows_plans
327-
print(plan)
334+
global active_plan_map, current_windows_plan, windows_plans, config
335+
if config['debug']:
336+
print(plan)
328337
active_plan_map[current_windows_plan] = False
329338
current_windows_plan = plan[1]
330339
active_plan_map[current_windows_plan] = True
@@ -360,9 +369,9 @@ def create_menu(): # This will create the menu in the tray app
360369
MenuItem("dGPU",
361370
Menu(
362371
MenuItem("dGPU ON", lambda: main_cmds.set_dgpu(True),
363-
checked=lambda menu_itm: (True if main_cmds.get_dgpu() else False)),
372+
checked=lambda menu_itm: (True if bool(main_cmds.get_dgpu()) else False)),
364373
MenuItem("dGPU OFF", lambda: main_cmds.set_dgpu(False),
365-
checked=lambda menu_itm: (False if main_cmds.get_dgpu() else True)),
374+
checked=lambda menu_itm: (False if bool(main_cmds.get_dgpu()) else True)),
366375
)),
367376
MenuItem("Screen Refresh",
368377
Menu(
@@ -464,7 +473,6 @@ def startup_checks():
464473
if __name__ == "__main__":
465474

466475
device = None
467-
frame = []
468476
G14dir = None
469477
get_app_path()
470478
config = load_config() # Make the config available to the whole script
@@ -490,8 +498,9 @@ if __name__ == "__main__":
490498
# Instantiate command line tasks runners in G14RunCommands.py
491499
main_cmds = RunCommands(config, G14dir, app_GUID,
492500
dpp_GUID, notify, windows_plans, active_plan_map)
493-
power_thread = power_check_thread()
494-
power_thread.start()
501+
if config['power_switch_enabled']:
502+
power_thread = power_check_thread()
503+
power_thread.start()
495504

496505
if config['default_gaming_plan'] is not None and config['default_gaming_plan_games'] is not None:
497506
gaming_thread = gaming_thread_impl('gaming-thread')

0 commit comments

Comments
 (0)