feat: Mimic GPU Screen Recorder UI and connect IPC configuration reloading

This commit is contained in:
katR 2026-09-02 07:24:14 +05:30
parent 826166d925
commit 5ec04365e1
5 changed files with 50 additions and 5 deletions

28
scratch/ipc_fix.patch Normal file
View file

@ -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);
+ }
+ }
+ }
}

View file

@ -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);
}
}
}
}

View file

@ -3,6 +3,9 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub enum Command {
SaveReplay,
StartRecording,
StopRecording,
ReloadConfig,
StopDaemon,
ShowOverlay,
}

View file

@ -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 {

View file

@ -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();
});