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 { 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 { 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) }