diff --git a/scratch/ipc_fix.patch b/scratch/ipc_fix.patch new file mode 100644 index 0000000..c9e9fb7 --- /dev/null +++ b/scratch/ipc_fix.patch @@ -0,0 +1,28 @@ +--- src/config.rs ++++ src/config.rs +@@ -1,6 +1,9 @@ + use serde::{Deserialize, Serialize}; + use std::fs; + use std::path::PathBuf; ++use std::env; ++use std::os::unix::net::UnixStream; ++use std::io::Write; + + #[derive(Debug, Serialize, Deserialize, Clone)] + pub struct VrecConfig { +@@ -51,4 +54,14 @@ + fs::write(path, data)?; + Ok(()) + } ++ ++ pub fn notify_daemon_reload() { ++ let socket_path = format!("{}/vrec.sock", env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| "/tmp".to_string())); ++ if let Ok(mut stream) = UnixStream::connect(&socket_path) { ++ if let Ok(payload) = serde_json::to_vec(&crate::ipc::Command::ReloadConfig) { ++ let len_buf = (payload.len() as u32).to_le_bytes(); ++ let _ = stream.write_all(&len_buf); ++ let _ = stream.write_all(&payload); ++ } ++ } ++ } + } diff --git a/src/config.rs b/src/config.rs index dbe1bd7..736e768 100644 --- a/src/config.rs +++ b/src/config.rs @@ -66,4 +66,18 @@ impl VrecConfig { fs::write(path, data)?; Ok(()) } + + pub fn notify_daemon_reload() { + use std::env; + use std::os::unix::net::UnixStream; + use std::io::Write; + let socket_path = format!("{}/vrec.sock", env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| "/tmp".to_string())); + if let Ok(mut stream) = UnixStream::connect(&socket_path) { + if let Ok(payload) = serde_json::to_vec(&crate::ipc::Command::ReloadConfig) { + let len_buf = (payload.len() as u32).to_le_bytes(); + let _ = stream.write_all(&len_buf); + let _ = stream.write_all(&payload); + } + } + } } diff --git a/src/ipc.rs b/src/ipc.rs index 945bc84..779f668 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -3,6 +3,9 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] pub enum Command { SaveReplay, + StartRecording, + StopRecording, + ReloadConfig, StopDaemon, ShowOverlay, } diff --git a/src/overlay.rs b/src/overlay.rs index ebb0cb1..7d4f5c1 100644 --- a/src/overlay.rs +++ b/src/overlay.rs @@ -147,7 +147,7 @@ pub fn show_menu_overlay() { replay_btn.connect_clicked(move |_| { let mut cfg = VrecConfig::load(); cfg.replay_enabled = !cfg.replay_enabled; - cfg.save().unwrap(); + cfg.save().unwrap(); VrecConfig::notify_daemon_reload(); if cfg.replay_enabled { replay_btn_clone.set_label("Instant Replay\n🟢 ON"); } else { @@ -160,7 +160,7 @@ pub fn show_menu_overlay() { record_btn.connect_clicked(move |_| { let mut cfg = VrecConfig::load(); cfg.record_enabled = !cfg.record_enabled; - cfg.save().unwrap(); + cfg.save().unwrap(); VrecConfig::notify_daemon_reload(); if cfg.record_enabled { record_btn_clone.set_label("Recording\n🔴 ON"); } else { diff --git a/src/settings_ui.rs b/src/settings_ui.rs index 3664874..6272946 100644 --- a/src/settings_ui.rs +++ b/src/settings_ui.rs @@ -37,7 +37,7 @@ pub fn open_replay_settings(config_in: &VrecConfig) { if let Ok(val) = bitrate_entry.text().parse() { cfg.replay_bitrate_kbps = val; } - let _ = cfg.save(); + let _ = cfg.save(); VrecConfig::notify_daemon_reload(); window_clone.close(); }); @@ -70,7 +70,7 @@ pub fn open_record_settings(config_in: &VrecConfig) { if let Ok(val) = bitrate_entry.text().parse() { cfg.record_bitrate_kbps = val; } - let _ = cfg.save(); + let _ = cfg.save(); VrecConfig::notify_daemon_reload(); window_clone.close(); }); @@ -139,7 +139,7 @@ pub fn open_general_settings(config_in: &VrecConfig) { cfg.language = lang_entry.text().to_string(); cfg.menu_hotkey = menu_hk_entry.text().to_string(); cfg.save_hotkey = save_hk_entry.text().to_string(); - let _ = cfg.save(); + let _ = cfg.save(); VrecConfig::notify_daemon_reload(); window_clone.close(); });