Files
fluxo-rs/src/modules/game.rs
T
nvrl bdbd6a8a40
Release / Build and Release (push) Has been cancelled
added tokio shared states instead of monolithic state
2026-04-02 18:11:21 +02:00

56 lines
1.6 KiB
Rust

use crate::config::Config;
use crate::error::Result;
use crate::modules::WaybarModule;
use crate::output::WaybarOutput;
use crate::state::AppReceivers;
use anyhow::anyhow;
use std::env;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::UnixStream;
pub struct GameModule;
impl WaybarModule for GameModule {
async fn run(
&self,
config: &Config,
_state: &AppReceivers,
_args: &[&str],
) -> Result<WaybarOutput> {
let is_gamemode = hyprland_ipc("j/getoption animations:enabled")
.await
.map(|stdout| stdout.contains("\"int\": 0"))
.unwrap_or(false);
if is_gamemode {
Ok(WaybarOutput {
text: config.game.format_active.clone(),
tooltip: Some("Gamemode activated".to_string()),
class: Some("active".to_string()),
percentage: None,
})
} else {
Ok(WaybarOutput {
text: config.game.format_inactive.clone(),
tooltip: Some("Gamemode deactivated".to_string()),
class: None,
percentage: None,
})
}
}
}
async fn hyprland_ipc(cmd: &str) -> Result<String> {
let signature = env::var("HYPRLAND_INSTANCE_SIGNATURE")
.map_err(|_| anyhow!("HYPRLAND_INSTANCE_SIGNATURE not set"))?;
let path = format!("/tmp/hypr/{}/.socket.sock", signature);
let mut stream = UnixStream::connect(path).await?;
stream.write_all(cmd.as_bytes()).await?;
let mut response = String::new();
stream.read_to_string(&mut response).await?;
Ok(response)
}