From cda1111cd33a3c0be50b76f023d2ab056f136737 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 2 Jan 2023 21:22:53 -0500 Subject: [PATCH] Add driver in debug UI and misc config stuff --- backend/Cargo.lock | 2 + backend/Cargo.toml | 2 +- backend/Dockerfile | 4 +- backend/src/api/general.rs | 29 ++++++++ backend/src/api/handler.rs | 9 +++ backend/src/main.rs | 4 ++ src/backend.ts | 4 ++ src/index.tsx | 9 +++ src/python.ts | 139 ------------------------------------- 9 files changed, 61 insertions(+), 141 deletions(-) delete mode 100644 src/python.ts diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 4a85e0f..01c9e77 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -886,6 +886,8 @@ checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "ryzenadj-rs" version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc77f2824d9c46759ba4907c8d3c3ca7131593a41fc389335bcdfda339a866bd" dependencies = [ "bindgen", ] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 8f8daec..c289281 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -21,7 +21,7 @@ simplelog = "0.12" # limits & driver functionality limits_core = { version = "0.1.0", path = "./limits_core" } regex = "1" -ryzenadj-rs = { version = "0.1", path = "../../ryzenadj-rs" } +ryzenadj-rs = { version = "0.1" } # ureq's tls feature does not like musl targets ureq = { version = "2.5", features = ["json", "gzip", "brotli", "charset"], default-features = false, optional = true } diff --git a/backend/Dockerfile b/backend/Dockerfile index f1a0ed3..94a2a88 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,3 +1,5 @@ FROM ghcr.io/steamdeckhomebrew/holo-toolchain-rust:latest -ENTRYPOINT [ "/backend/entrypoint.sh" ] \ No newline at end of file +RUN pacman -S --noconfirm cmake make + +ENTRYPOINT [ "/backend/entrypoint.sh" ] diff --git a/backend/src/api/general.rs b/backend/src/api/general.rs index 32e040b..309203d 100644 --- a/backend/src/api/general.rs +++ b/backend/src/api/general.rs @@ -178,6 +178,35 @@ pub fn get_limits( } } +/// Generate get current driver name +pub fn get_provider( + sender: Sender, +) -> impl AsyncCallable { + let sender = Arc::new(Mutex::new(sender)); // Sender is not Sync; this is required for safety + let getter = move || { + let sender2 = sender.clone(); + move |provider_name: String| { + let (tx, rx) = mpsc::channel(); + let callback = move |name: crate::persist::DriverJson| tx.send(name).expect("get_provider callback send failed"); + sender2.lock().unwrap().send(ApiMessage::GetProvider(provider_name, Box::new(callback))).expect("get_provider send failed"); + rx.recv().expect("get_provider callback recv failed") + } + }; + super::async_utils::AsyncIsh { + trans_setter: |mut params| { + if let Some(Primitive::String(name)) = params.pop() { + Ok(name.to_owned()) + } else { + Err(format!("Invalid/missing single param in get_provider")) + } + }, + set_get: getter, + trans_getter: |result| { + vec![format!("{:?}", result).into()] + } + } +} + pub fn gunter(_: super::ApiParameterType) -> super::ApiParameterType { std::thread::spawn(|| { log::info!("Zhu Li, do the thing!"); diff --git a/backend/src/api/handler.rs b/backend/src/api/handler.rs index cd77ed3..a1a9354 100644 --- a/backend/src/api/handler.rs +++ b/backend/src/api/handler.rs @@ -17,6 +17,7 @@ pub enum ApiMessage { LoadMainSettings, LoadSystemSettings, GetLimits(Callback), + GetProvider(String, Callback), } pub enum BatteryMessage { @@ -221,6 +222,14 @@ impl ApiMessageHandler { gpu: settings.gpu.limits(), general: settings.general.limits(), }); + }, + ApiMessage::GetProvider(name, cb) => { + cb(match &name as &str { + "battery" => settings.battery.provider(), + "cpu" | "cpus" => settings.cpus.provider(), + "gpu" => settings.gpu.provider(), + _ => settings.general.provider(), + }) } } } diff --git a/backend/src/main.rs b/backend/src/main.rs index e949d30..8390b97 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -212,6 +212,10 @@ fn main() -> Result<(), ()> { "GENERAL_get_limits", api::general::get_limits(api_sender.clone()) ) + .register_async( + "GENERAL_get_provider", + api::general::get_provider(api_sender.clone()) + ) .register("GENERAL_idk", api::general::gunter); api_worker::spawn(loaded_settings, api_handler); diff --git a/src/backend.ts b/src/backend.ts index d736630..53a1c9d 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -227,6 +227,10 @@ export async function getLimits(): Promise { return (await call_backend("GENERAL_get_limits", []))[0]; } +export async function getDriverProviderName(name: string): Promise { + return (await call_backend("GENERAL_get_provider", [name]))[0]; +} + export async function idk(): Promise { return (await call_backend("GENERAL_idk", []))[0]; } diff --git a/src/index.tsx b/src/index.tsx index 0391718..b804bcd 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -46,6 +46,7 @@ type MinMax = { // usdpl persistent store keys const BACKEND_INFO = "VINFO"; +const DRIVER_INFO = "GENERAL_provider"; const LIMITS_INFO = "LIMITS_all"; @@ -144,6 +145,7 @@ const reload = function() { backend.resolve(backend.getGeneralSettingsName(), (name: string) => { set_value(NAME_GEN, name) }); backend.resolve(backend.getInfo(), (info: string) => { set_value(BACKEND_INFO, info) }); + backend.resolve(backend.getDriverProviderName("gpu"), (driver: string) => { set_value(DRIVER_INFO, driver) }); }; // init USDPL WASM and connection to back-end @@ -842,6 +844,13 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => { {eggCount % 10 == 9 ? "<3 <3 <3" : target_usdpl()} + + eggCount++}> + {eggCount % 10 == 9 ? "Tracy Chapman" : get_value(DRIVER_INFO)} + + , setter: any) { - (async function () { - let data = await promise; - if (data.success) { - console.debug("Got resolved", data, "promise", promise); - setter(data.result); - } else { - console.warn("Resolve failed:", data, "promise", promise); - } - })(); -} - -export function execute(promise: Promise) { - (async function () { - let data = await promise; - if (data.success) { - console.debug("Got executed", data, "promise", promise); - } else { - console.warn("Execute failed:", data, "promise", promise); - } - - })(); -} - -export function setServer(s: ServerAPI) { - server = s; -} - -// Python functions -export function getVersion(): Promise { - return server!.callPluginMethod("get_version", {}); -} - -export function onViewReady(): Promise { - return server!.callPluginMethod("on_ready", {}); -} - -export function setCPUs(value: number, smt: boolean): Promise { - return server!.callPluginMethod("set_cpus", {"count":value, "smt": smt}); -} - -export function getCPUs(): Promise { - return server!.callPluginMethod("get_cpus", {}); -} - -export function getSMT(): Promise { - return server!.callPluginMethod("get_smt", {}); -} - -export function setCPUBoost(value: boolean): Promise { - return server!.callPluginMethod("set_boost", {"enabled": value}); -} - -export function getCPUBoost(): Promise { - return server!.callPluginMethod("get_boost", {}); -} - -export function setMaxBoost(index: number): Promise { - return server!.callPluginMethod("set_max_boost", {"index": index}); -} - -export function getMaxBoost(): Promise { - return server!.callPluginMethod("get_max_boost", {}); -} - -export function setGPUPower(value: number, index: number): Promise { - return server!.callPluginMethod("set_gpu_power", {"value": value, "power_number": index}); -} - -export function getGPUPower(index: number): Promise { - return server!.callPluginMethod("get_gpu_power", {"power_number": index}); -} - -export function setGPUPowerI(value: number, index: number): Promise { - return server!.callPluginMethod("set_gpu_power_index", {"index": value, "power_number": index}); -} - -export function getGPUPowerI(index: number): Promise { - return server!.callPluginMethod("get_gpu_power_index", {"power_number": index}); -} - -export function setFanTick(tick: number): Promise { - return server!.callPluginMethod("set_fan_tick", {"tick": tick}); -} - -export function getFanTick(): Promise { - return server!.callPluginMethod("get_fan_tick", {}); -} - -export function getFantastic(): Promise { - return server!.callPluginMethod("fantastic_installed", {}); -} - -export function getChargeNow(): Promise { - return server!.callPluginMethod("get_charge_now", {}); -} - -export function getChargeFull(): Promise { - return server!.callPluginMethod("get_charge_full", {}); -} - -export function getChargeDesign(): Promise { - return server!.callPluginMethod("get_charge_design", {}); -} - -export function setPersistent(value: boolean): Promise { - return server!.callPluginMethod("set_persistent", {"enabled": value}); -} - -export function getPersistent(): Promise { - return server!.callPluginMethod("get_persistent", {}); -} - -export function setPerGameProfile(value: boolean): Promise { - return server!.callPluginMethod("set_per_game_profile", {"enabled": value}); -} - -export function getPerGameProfile(): Promise { - return server!.callPluginMethod("get_per_game_profile", {}); -} - -export function getCurrentGame(): Promise { - return server!.callPluginMethod("get_current_game", {}); -} - -export function onGameStart(gameId: number, data: any): Promise { - const data2 = {appid: data.appid, display_name: data.display_name, gameid: gameId}; // Issue #17 - return server!.callPluginMethod("on_game_start", {"game_id": gameId, "data":data2}); -} - -export function onGameStop(gameId: number | null): Promise { - return server!.callPluginMethod("on_game_stop", {"game_id": gameId}); -}