Set custom power plan name and sleep timeouts

This commit is contained in:
2Shirt 2021-10-27 18:03:52 -06:00
parent d3f5cccdb2
commit a18a8f8156
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 24 additions and 3 deletions

View file

@ -59,11 +59,16 @@ BLEACH_BIT_CLEANERS = (
'windows_explorer.run',
'windows_explorer.thumbnails',
)
CUSTOM_POWER_PLAN_NAME = f'{KIT_NAME_FULL} Power Plan'
POWER_PLANS = {
'Balanced': '381b4222-f694-41f0-9685-ff5bb260df2e',
'Custom': '01189998-8199-9119-725c-ccccccccccc3',
'High Performance': '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c',
}
POWER_PLAN_SLEEP_TIMEOUTS = {
'Balanced': ('1800', '900'),
'High Performance': ('0', '0'),
}
REG_UAC_DEFAULTS_WIN7 = {
'HKLM': {
r'Software\Microsoft\Windows\CurrentVersion\Policies\System': (

View file

@ -16,7 +16,9 @@ from wk.cfg.repairs import (
AUTO_REPAIR_DELAY_IN_SECONDS,
AUTO_REPAIR_KEY,
BLEACH_BIT_CLEANERS,
CUSTOM_POWER_PLAN_NAME,
POWER_PLANS,
POWER_PLAN_SLEEP_TIMEOUTS,
REG_UAC_DEFAULTS_WIN7,
REG_UAC_DEFAULTS_WIN10,
WIDTH,
@ -732,6 +734,7 @@ def auto_set_custom_power_plan(group, name):
"""Set custom power plan."""
result = TRY_PRINT.run(
'Set Custom Power Plan...', create_custom_power_plan,
enable_sleep=False,
keep_display_on=True,
)
save_settings(group, name, result=result)
@ -1068,19 +1071,24 @@ def run_tdsskiller():
# OS Built-in Functions
def create_custom_power_plan(keep_display_on=False):
def create_custom_power_plan(enable_sleep=True, keep_display_on=False):
"""Create new power plan and set as active."""
custom_guid = POWER_PLANS['Custom']
sleep_timeouts = POWER_PLAN_SLEEP_TIMEOUTS['High Performance']
if enable_sleep:
sleep_timeouts = POWER_PLAN_SLEEP_TIMEOUTS['Balanced']
# Duplicate High Performance plan
cmd = [
'powercfg', '-DuplicateScheme',
POWER_PLANS['High Performance'], custom_guid,
]
run_program(cmd)
proc = run_program(cmd, check=False)
if proc.returncode and 'GUID already exists' not in proc.stderr:
LOG.error("Failed to create custom power plan.\n Details: %s", proc)
# Change the name
cmd = ['powercfg', '-ChangeName', custom_guid, KIT_NAME_FULL]
cmd = ['powercfg', '-ChangeName', custom_guid, CUSTOM_POWER_PLAN_NAME]
run_program(cmd)
# Set as active plan
@ -1100,6 +1108,14 @@ def create_custom_power_plan(keep_display_on=False):
]
run_program(cmd)
# Set sleep values
for arg, value in zip(
('-SetacValueIndex', '-SetdcValueIndex'), sleep_timeouts):
cmd = [
'powercfg', arg, custom_guid, 'SUB_SLEEP', 'STANDBYIDLE', value,
]
run_program(cmd)
def create_system_restore_point():
"""Create System Restore point."""