Set custom power plan name and sleep timeouts
This commit is contained in:
parent
d3f5cccdb2
commit
a18a8f8156
2 changed files with 24 additions and 3 deletions
|
|
@ -59,11 +59,16 @@ BLEACH_BIT_CLEANERS = (
|
||||||
'windows_explorer.run',
|
'windows_explorer.run',
|
||||||
'windows_explorer.thumbnails',
|
'windows_explorer.thumbnails',
|
||||||
)
|
)
|
||||||
|
CUSTOM_POWER_PLAN_NAME = f'{KIT_NAME_FULL} Power Plan'
|
||||||
POWER_PLANS = {
|
POWER_PLANS = {
|
||||||
'Balanced': '381b4222-f694-41f0-9685-ff5bb260df2e',
|
'Balanced': '381b4222-f694-41f0-9685-ff5bb260df2e',
|
||||||
'Custom': '01189998-8199-9119-725c-ccccccccccc3',
|
'Custom': '01189998-8199-9119-725c-ccccccccccc3',
|
||||||
'High Performance': '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c',
|
'High Performance': '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c',
|
||||||
}
|
}
|
||||||
|
POWER_PLAN_SLEEP_TIMEOUTS = {
|
||||||
|
'Balanced': ('1800', '900'),
|
||||||
|
'High Performance': ('0', '0'),
|
||||||
|
}
|
||||||
REG_UAC_DEFAULTS_WIN7 = {
|
REG_UAC_DEFAULTS_WIN7 = {
|
||||||
'HKLM': {
|
'HKLM': {
|
||||||
r'Software\Microsoft\Windows\CurrentVersion\Policies\System': (
|
r'Software\Microsoft\Windows\CurrentVersion\Policies\System': (
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@ from wk.cfg.repairs import (
|
||||||
AUTO_REPAIR_DELAY_IN_SECONDS,
|
AUTO_REPAIR_DELAY_IN_SECONDS,
|
||||||
AUTO_REPAIR_KEY,
|
AUTO_REPAIR_KEY,
|
||||||
BLEACH_BIT_CLEANERS,
|
BLEACH_BIT_CLEANERS,
|
||||||
|
CUSTOM_POWER_PLAN_NAME,
|
||||||
POWER_PLANS,
|
POWER_PLANS,
|
||||||
|
POWER_PLAN_SLEEP_TIMEOUTS,
|
||||||
REG_UAC_DEFAULTS_WIN7,
|
REG_UAC_DEFAULTS_WIN7,
|
||||||
REG_UAC_DEFAULTS_WIN10,
|
REG_UAC_DEFAULTS_WIN10,
|
||||||
WIDTH,
|
WIDTH,
|
||||||
|
|
@ -732,6 +734,7 @@ def auto_set_custom_power_plan(group, name):
|
||||||
"""Set custom power plan."""
|
"""Set custom power plan."""
|
||||||
result = TRY_PRINT.run(
|
result = TRY_PRINT.run(
|
||||||
'Set Custom Power Plan...', create_custom_power_plan,
|
'Set Custom Power Plan...', create_custom_power_plan,
|
||||||
|
enable_sleep=False,
|
||||||
keep_display_on=True,
|
keep_display_on=True,
|
||||||
)
|
)
|
||||||
save_settings(group, name, result=result)
|
save_settings(group, name, result=result)
|
||||||
|
|
@ -1068,19 +1071,24 @@ def run_tdsskiller():
|
||||||
|
|
||||||
|
|
||||||
# OS Built-in Functions
|
# 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."""
|
"""Create new power plan and set as active."""
|
||||||
custom_guid = POWER_PLANS['Custom']
|
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
|
# Duplicate High Performance plan
|
||||||
cmd = [
|
cmd = [
|
||||||
'powercfg', '-DuplicateScheme',
|
'powercfg', '-DuplicateScheme',
|
||||||
POWER_PLANS['High Performance'], custom_guid,
|
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
|
# Change the name
|
||||||
cmd = ['powercfg', '-ChangeName', custom_guid, KIT_NAME_FULL]
|
cmd = ['powercfg', '-ChangeName', custom_guid, CUSTOM_POWER_PLAN_NAME]
|
||||||
run_program(cmd)
|
run_program(cmd)
|
||||||
|
|
||||||
# Set as active plan
|
# Set as active plan
|
||||||
|
|
@ -1100,6 +1108,14 @@ def create_custom_power_plan(keep_display_on=False):
|
||||||
]
|
]
|
||||||
run_program(cmd)
|
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():
|
def create_system_restore_point():
|
||||||
"""Create System Restore point."""
|
"""Create System Restore point."""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue