diff --git a/Cargo.toml b/Cargo.toml index d44c732..a94fbcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ tokio = { version = "1.47", features = ["rt-multi-thread", "macros", "time"] } log = "0.4" simplelog = "0.12" sysinfo = "0.37" +gfxinfo = { version = "0.1", features = ["default"] } diff --git a/README.md b/README.md index 901aab1..8524c83 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,6 @@ An OpenAction ([OpenDeck](https://github.com/nekename/OpenDeck) / [Tacto](https: - CPU - RAM +- GPU - Uptime - OS diff --git a/assets/manifest.json b/assets/manifest.json index 9035adf..cd24104 100644 --- a/assets/manifest.json +++ b/assets/manifest.json @@ -32,6 +32,14 @@ "Controllers": ["Keypad", "Encoder"], "States": [{ "Title": "0GB", "FontSize": 14 }] }, + { + "UUID": "me.amankhanna.oasystem.gpu", + "Name": "GPU", + "Icon": "icon", + "Tooltip": "Displays GPU utilisation", + "Controllers": ["Keypad", "Encoder"], + "States": [{ "Title": "0%", "FontSize": 16 }] + }, { "UUID": "me.amankhanna.oasystem.uptime", "Name": "Uptime", diff --git a/src/main.rs b/src/main.rs index 4415d38..05fac67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use openaction::*; +use gfxinfo::active_gpu; use sysinfo::System; struct CPUAction; @@ -18,6 +19,13 @@ impl Action for RAMAction { type Settings = HashMap; } +struct GPUAction; +#[async_trait] +impl Action for GPUAction { + const UUID: ActionUuid = "me.amankhanna.oasystem.gpu"; + type Settings = HashMap; +} + struct UptimeAction; #[async_trait] impl Action for UptimeAction { @@ -81,6 +89,15 @@ async fn main() -> OpenActionResult<()> { let _ = instance.set_title(Some(ram_usage.clone()), None).await; } + let gpu_usage = if let Ok(gpu) = active_gpu() { + format!("{:.0}%", gpu.info().load_pct()) + } else { + "No GPU found".to_owned() + }; + for instance in visible_instances(GPUAction::UUID).await { + let _ = instance.set_title(Some(gpu_usage.clone()), None).await; + } + { let total_secs = System::uptime(); let days = total_secs / 86_400; @@ -102,6 +119,7 @@ async fn main() -> OpenActionResult<()> { register_action(CPUAction).await; register_action(RAMAction).await; + register_action(GPUAction).await; register_action(UptimeAction).await; register_action(OSAction).await;