From b3de3fcd7e09d9d909937983d2b8fef850f2a956 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Fri, 25 Nov 2022 20:56:35 -0500 Subject: [PATCH] Directly disable jupiter-fan-control service to fix #10 --- backend-rs/Cargo.lock | 2 +- backend-rs/Cargo.toml | 2 +- backend-rs/build.sh | 12 ++++++--- backend-rs/src/control.rs | 51 ++++++++++++++++++++++++++++++++++++++- package.json | 2 +- src/index.tsx | 7 +----- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/backend-rs/Cargo.lock b/backend-rs/Cargo.lock index 055301a..671a3da 100644 --- a/backend-rs/Cargo.lock +++ b/backend-rs/Cargo.lock @@ -106,7 +106,7 @@ dependencies = [ [[package]] name = "fantastic-rs" -version = "0.3.3" +version = "0.3.5" dependencies = [ "log", "serde", diff --git a/backend-rs/Cargo.toml b/backend-rs/Cargo.toml index 6dbe29e..7dd63cb 100644 --- a/backend-rs/Cargo.toml +++ b/backend-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fantastic-rs" -version = "0.3.3" +version = "0.3.5" edition = "2021" [dependencies] diff --git a/backend-rs/build.sh b/backend-rs/build.sh index 9f60798..08d6ef3 100755 --- a/backend-rs/build.sh +++ b/backend-rs/build.sh @@ -1,5 +1,11 @@ #!/bin/bash -cross build --release -mkdir ../bin -cp ./target/release/fantastic-rs ../bin/backend +#cargo build --release --target x86_64-unknown-linux-musl +cargo build --target x86_64-unknown-linux-musl +#cross build --release + +mkdir -p ../bin +#cp ./target/x86_64-unknown-linux-musl/release/fantastic-rs ../bin/backend +cp ./target/x86_64-unknown-linux-musl/debug/fantastic-rs ../bin/backend +#cp ./target/release/fantastic-rs ../bin/backend + diff --git a/backend-rs/src/control.rs b/backend-rs/src/control.rs index a269784..c53a455 100644 --- a/backend-rs/src/control.rs +++ b/backend-rs/src/control.rs @@ -8,6 +8,8 @@ use std::time::{Duration, Instant}; use super::datastructs::{Settings, State, GraphPoint}; use super::json::SettingsJson; +const VALVE_FAN_SERVICE: &str = "jupiter-fan-control.service"; + pub struct ControlRuntime { settings: Arc>, state: Arc>, @@ -104,6 +106,7 @@ impl ControlRuntime { } }; if settings.enable { + Self::enforce_jupiter_status(true); Self::do_fan_control(&settings); } } @@ -113,7 +116,8 @@ impl ControlRuntime { } fn on_set_enable(settings: &Settings, _state: &State) { - // TODO stop/start jupiter fan control (or maybe let the UI handle that?) + // stop/start jupiter fan control (since the client-side way of doing this was removed :( ) + Self::enforce_jupiter_status(settings.enable); if let Err(e) = crate::sys::write_fan_recalc(settings.enable) { log::error!("runtime failed to write to fan recalculate file: {}", e); } @@ -222,6 +226,51 @@ impl ControlRuntime { } } } + + fn enforce_jupiter_status(enabled: bool) { + // enabled refers to whether this plugin's functionality is enabled, + // not the jupiter fan control service + let service_status = Self::detect_jupiter_fan_service(); + log::debug!("fan control service is enabled? {}", service_status); + if enabled == service_status { + // do not run Valve's fan service along with Fantastic, since they fight + if enabled { + Self::stop_fan_service(); + } else { + Self::start_fan_service(); + } + } + } + + fn detect_jupiter_fan_service() -> bool { + match std::process::Command::new("systemctl") + .args(["is-active", VALVE_FAN_SERVICE]) + .output() { + Ok(cmd) => String::from_utf8_lossy(&cmd.stdout).trim() == "active", + Err(e) => { + log::error!("`systemctl is-active {}` err: {}", VALVE_FAN_SERVICE, e); + false + } + } + } + + fn start_fan_service() { + match std::process::Command::new("systemctl") + .args(["start", VALVE_FAN_SERVICE]) + .output() { + Err(e) => log::error!("`systemctl start {}` err: {}", VALVE_FAN_SERVICE, e), + Ok(out) => log::debug!("started `{}`:\nstdout:{}\nstderr:{}", VALVE_FAN_SERVICE, String::from_utf8_lossy(&out.stdout), String::from_utf8_lossy(&out.stderr)), + } + } + + fn stop_fan_service() { + match std::process::Command::new("systemctl") + .args(["stop", VALVE_FAN_SERVICE]) + .output() { + Err(e) => log::error!("`systemctl stop {}` err: {}", VALVE_FAN_SERVICE, e), + Ok(out) => log::debug!("stopped `{}`:\nstdout:{}\nstderr:{}", VALVE_FAN_SERVICE, String::from_utf8_lossy(&out.stdout), String::from_utf8_lossy(&out.stderr)), + } + } } fn settings_path>(home: P) -> std::path::PathBuf { diff --git a/package.json b/package.json index 1968a23..d5a7432 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Fantastic", - "version": "0.3.4", + "version": "0.3.5", "description": "A template to quickly create decky plugins from scratch, based on TypeScript and webpack", "scripts": { "build": "shx rm -rf dist && rollup -c", diff --git a/src/index.tsx b/src/index.tsx index b8c6e35..81dedb7 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -55,8 +55,6 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => { function setEnable(enable: boolean) { setEnableInternal(enable); - //@ts-ignore - SteamClient.System.SetBetaFanControl(!enable); } function onClickCanvas(e: any) { @@ -290,10 +288,7 @@ export default definePlugin((serverApi: ServerAPI) => { (async function(){ await backend.initBackend(); usdplReady = true; - backend.getEnabled().then((enabled: boolean) => { - //@ts-ignore - SteamClient.System.SetBetaFanControl(!enabled); - }); + backend.getEnabled(); })(); let ico = ;