Skip to content

Commit

Permalink
main: only debug with config option
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Mar 21, 2024
1 parent b059641 commit 6e800ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
monitor: "DP-1"
wallpapers: "/nix/store/xl4p5kciyn2kahc3kpafvgjwqlj0q8yy-khanelinix.wallpapers/share/wallpapers/"
debug: false
40 changes: 23 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,28 @@ use serde::Deserialize;
pub struct Config {
pub monitor: String,
pub wallpapers: String,
pub debug: Option<bool>,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
println!("Loading config...");
let proj_dirs = ProjectDirs::from("com", "khaneliman", "hypr-socket-watch");
let config_path = proj_dirs
.expect("No config found")
.config_dir()
.join("config.yaml");

let mut config_file = File::open(&config_path)?;
let mut config_str = String::new();
config_file.read_to_string(&mut config_str)?;

let config: Config = serde_yaml::from_str(&config_str).expect("error getting config");

if config.debug.is_some() && config.debug.unwrap() {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
}

// Get the socket path from the environment variable
let hyprland_instance_signature = env::var("HYPRLAND_INSTANCE_SIGNATURE")?;
Expand All @@ -35,25 +51,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to the socket using UnixStream
let stream = UnixStream::connect(socket_path).await?;

handle_loop(stream).await?;
handle_loop(stream, &config).await?;

Ok(())
}

async fn handle_loop(stream: UnixStream) -> Result<(), Box<dyn std::error::Error>> {
println!("Loading config...");
let proj_dirs = ProjectDirs::from("com", "khaneliman", "hypr-socket-watch");
let config_path = proj_dirs
.expect("No config found")
.config_dir()
.join("config.yaml");

let mut config_file = File::open(&config_path)?;
let mut config_str = String::new();
config_file.read_to_string(&mut config_str)?;

let config: Config = serde_yaml::from_str(&config_str).expect("error getting config");

async fn handle_loop(
stream: UnixStream,
config: &Config,
) -> Result<(), Box<dyn std::error::Error>> {
const LINE_ENDING: &str = "\n";
let mut buffer = vec![0; 128]; // Adjust buffer size as needed
let mut line_buffer = String::new();
Expand Down

0 comments on commit 6e800ea

Please sign in to comment.