Directly disable jupiter-fan-control service to fix #10

This commit is contained in:
NGnius (Graham) 2022-11-25 20:56:35 -05:00
parent 2286e0f43a
commit b3de3fcd7e
6 changed files with 63 additions and 13 deletions

2
backend-rs/Cargo.lock generated
View file

@ -106,7 +106,7 @@ dependencies = [
[[package]]
name = "fantastic-rs"
version = "0.3.3"
version = "0.3.5"
dependencies = [
"log",
"serde",

View file

@ -1,6 +1,6 @@
[package]
name = "fantastic-rs"
version = "0.3.3"
version = "0.3.5"
edition = "2021"
[dependencies]

View file

@ -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

View file

@ -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<RwLock<Settings>>,
state: Arc<RwLock<State>>,
@ -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<P: AsRef<std::path::Path>>(home: P) -> std::path::PathBuf {

View file

@ -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",

View file

@ -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 = <FaFan />;