added tokio shared states instead of monolithic state
Release / Build and Release (push) Has been cancelled
Release / Build and Release (push) Has been cancelled
This commit is contained in:
+9
-8
@@ -2,11 +2,11 @@ use crate::config::Config;
|
||||
use crate::error::Result;
|
||||
use crate::modules::WaybarModule;
|
||||
use crate::output::WaybarOutput;
|
||||
use crate::state::SharedState;
|
||||
use crate::state::AppReceivers;
|
||||
use anyhow::anyhow;
|
||||
use std::env;
|
||||
use std::io::{Read, Write};
|
||||
use std::os::unix::net::UnixStream;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
pub struct GameModule;
|
||||
|
||||
@@ -14,10 +14,11 @@ impl WaybarModule for GameModule {
|
||||
async fn run(
|
||||
&self,
|
||||
config: &Config,
|
||||
_state: &SharedState,
|
||||
_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);
|
||||
|
||||
@@ -39,16 +40,16 @@ impl WaybarModule for GameModule {
|
||||
}
|
||||
}
|
||||
|
||||
fn hyprland_ipc(cmd: &str) -> Result<String> {
|
||||
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)?;
|
||||
stream.write_all(cmd.as_bytes())?;
|
||||
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)?;
|
||||
stream.read_to_string(&mut response).await?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user