Add CPU Boost toggle
This commit is contained in:
parent
75c75eea77
commit
900d92ec96
2 changed files with 58 additions and 0 deletions
7
main.py
7
main.py
|
@ -24,6 +24,13 @@ class Plugin:
|
||||||
for cpu in range(1, self.CPU_COUNT):
|
for cpu in range(1, self.CPU_COUNT):
|
||||||
online_count += int(status_cpu(cpu))
|
online_count += int(status_cpu(cpu))
|
||||||
return online_count
|
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
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
||||||
async def _main(self):
|
async def _main(self):
|
||||||
|
|
|
@ -14,6 +14,14 @@
|
||||||
return call_plugin_method("get_cpus", {});
|
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
|
// other logic
|
||||||
|
|
||||||
async function onSetCPUs() {
|
async function onSetCPUs() {
|
||||||
|
@ -24,6 +32,8 @@
|
||||||
|
|
||||||
async function onReady() {
|
async function onReady() {
|
||||||
document.getElementById("cpu_threads").value = await getCPUs();
|
document.getElementById("cpu_threads").value = await getCPUs();
|
||||||
|
let boostToggle = document.getElementById("boostToggle");
|
||||||
|
setToggleState(boostToggle, await getCPUBoost());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function decrementCPUs() {
|
async function decrementCPUs() {
|
||||||
|
@ -48,6 +58,28 @@
|
||||||
await onSetCPUs();
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style type="text/css" media="screen">
|
<style type="text/css" media="screen">
|
||||||
input::-webkit-outer-spin-button,
|
input::-webkit-outer-spin-button,
|
||||||
|
@ -65,5 +97,24 @@
|
||||||
<button type="button" onclick="decrementCPUs()">\/</button>
|
<button type="button" onclick="decrementCPUs()">\/</button>
|
||||||
<button type="button" onclick="resetCPUs()">Reset</button>
|
<button type="button" onclick="resetCPUs()">Reset</button>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Toggle switch, roughly copied from https://github.com/SteamDeckHomebrew/ExtraSettingsPlugin/blob/main/main_view.html -->
|
||||||
|
<div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable">
|
||||||
|
<div class="quickaccesscontrols_PanelSectionRow_26R5w">
|
||||||
|
<div class="quickaccesscontrols_PanelSectionRow_26R5w">
|
||||||
|
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_WithBottomSeparator_3YKpU gamepaddialog_ExtraPaddingOnChildrenBelow_3nLNL gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable" style="--indent-level:0;">
|
||||||
|
<div class="gamepaddialog_FieldLabelRow_2VcTl">
|
||||||
|
<div class="gamepaddialog_FieldLabel_3jMlJ">
|
||||||
|
CPU Boost
|
||||||
|
</div>
|
||||||
|
<div class="gamepaddialog_FieldChildren_2rhav">
|
||||||
|
<div id="boostToggle" tabindex="0" class="gamepaddialog_Toggle_9Ql-o Focusable" onclick="toggleCPUBoost()">
|
||||||
|
<div class="gamepaddialog_ToggleRail_2bl0i"></div>
|
||||||
|
<div class="gamepaddialog_ToggleSwitch_1PQpp"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue