From 900d92ec966e30d4da4d0554e270b21a7d68235f Mon Sep 17 00:00:00 2001 From: NGnius Date: Thu, 21 Apr 2022 16:17:23 -0400 Subject: [PATCH] Add CPU Boost toggle --- main.py | 7 +++++++ main_view.html | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/main.py b/main.py index 08c80e7..9ae293d 100644 --- a/main.py +++ b/main.py @@ -24,6 +24,13 @@ class Plugin: for cpu in range(1, self.CPU_COUNT): online_count += int(status_cpu(cpu)) return online_count + + async def set_boost(self, enabled: bool) -> bool: + write_to_sys("/sys/devices/system/cpu/cpufreq/boost", int(enabled)) + return True + + async def get_boost(self) -> bool: + return read_from_sys("/sys/devices/system/cpu/cpufreq/boost") == "1" # Asyncio-compatible long-running code, executed in a task when the plugin is loaded async def _main(self): diff --git a/main_view.html b/main_view.html index 1f60259..9a100d0 100644 --- a/main_view.html +++ b/main_view.html @@ -14,6 +14,14 @@ return call_plugin_method("get_cpus", {}); } + function setCPUBoost(value) { + return call_plugin_method("set_boost", {"enabled": value}); + } + + function getCPUBoost() { + return call_plugin_method("get_boost", {}); + } + // other logic async function onSetCPUs() { @@ -24,6 +32,8 @@ async function onReady() { document.getElementById("cpu_threads").value = await getCPUs(); + let boostToggle = document.getElementById("boostToggle"); + setToggleState(boostToggle, await getCPUBoost()); } async function decrementCPUs() { @@ -48,6 +58,28 @@ await onSetCPUs(); } + function setToggleState(toggle, state) { + const ENABLED_CLASS = "gamepaddialog_On_yLrDA"; + if (state && !toggle.classList.contains(ENABLED_CLASS)) { + toggle.classList.add(ENABLED_CLASS); + } + + if (!state && toggle.classList.contains(ENABLED_CLASS)) { + toggle.classList.remove(ENABLED_CLASS); + } + } + + function getToggleState(toggle) { + return toggle.classList.contains("gamepaddialog_On_yLrDA"); + } + + async function toggleCPUBoost() { + let toggle = document.getElementById("boostToggle"); + let isActive = getToggleState(toggle); + await setCPUBoost(!isActive); + setToggleState(toggle, await getCPUBoost()); + } +