From 304780922448823873603f101dd09ca57224186e Mon Sep 17 00:00:00 2001 From: oiupoyt Date: Fri, 4 Sep 2026 23:48:23 +0530 Subject: [PATCH] chore(code-quality): clean clippy lints and improve Wayland source selection --- src/bin/vrec-daemon.rs | 10 ++++------ src/bin/vrec-ui.rs | 5 ++--- src/capture/audio.rs | 11 +++++------ src/capture/wayland.rs | 2 +- src/config.rs | 14 ++++++-------- src/hyprland_binds.rs | 5 ++--- src/overlay_egui.rs | 18 +++++++++++------- 7 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/bin/vrec-daemon.rs b/src/bin/vrec-daemon.rs index 84990ab..54c63fe 100644 --- a/src/bin/vrec-daemon.rs +++ b/src/bin/vrec-daemon.rs @@ -17,8 +17,8 @@ fn ensure_wayland_env() { { let runtime_dir = env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| format!("/run/user/{}", unsafe { libc::getuid() })); unsafe { - if env::var("WAYLAND_DISPLAY").is_err() { - if let Ok(entries) = std::fs::read_dir(&runtime_dir) { + if env::var("WAYLAND_DISPLAY").is_err() + && let Ok(entries) = std::fs::read_dir(&runtime_dir) { for entry in entries.flatten() { let name = entry.file_name().to_string_lossy().to_string(); if name.starts_with("wayland-") && !name.ends_with(".lock") { @@ -27,7 +27,6 @@ fn ensure_wayland_env() { break; } } - } } if env::var("DBUS_SESSION_BUS_ADDRESS").is_err() { let bus_path = format!("{}/bus", runtime_dir); @@ -235,8 +234,8 @@ async fn main() -> Result<(), Box> { }; prepared.push((time_us, rebased)); } - } else if p.stream_index() == 1 { - if p.pts() >= first_audio_pts { + } else if p.stream_index() == 1 + && p.pts() >= first_audio_pts { let rebased = p.rebased(first_audio_pts); let time_us = if let Some(a_tb) = audio_time_base { unsafe { @@ -250,7 +249,6 @@ async fn main() -> Result<(), Box> { 0 }; prepared.push((time_us, rebased)); - } } } diff --git a/src/bin/vrec-ui.rs b/src/bin/vrec-ui.rs index 650543e..1a53ef4 100644 --- a/src/bin/vrec-ui.rs +++ b/src/bin/vrec-ui.rs @@ -8,8 +8,8 @@ fn ensure_wayland_env() { { let runtime_dir = env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| format!("/run/user/{}", unsafe { libc::getuid() })); unsafe { - if env::var("WAYLAND_DISPLAY").is_err() { - if let Ok(entries) = std::fs::read_dir(&runtime_dir) { + if env::var("WAYLAND_DISPLAY").is_err() + && let Ok(entries) = std::fs::read_dir(&runtime_dir) { for entry in entries.flatten() { let name = entry.file_name().to_string_lossy().to_string(); if name.starts_with("wayland-") && !name.ends_with(".lock") { @@ -17,7 +17,6 @@ fn ensure_wayland_env() { break; } } - } } if env::var("DBUS_SESSION_BUS_ADDRESS").is_err() { let bus_path = format!("{}/bus", runtime_dir); diff --git a/src/capture/audio.rs b/src/capture/audio.rs index eecefd2..af2b958 100644 --- a/src/capture/audio.rs +++ b/src/capture/audio.rs @@ -275,12 +275,11 @@ impl AudioCapture { let find_mic_device = || -> Option { if let Some(target) = device_name && target != "default" - && !target.trim().is_empty() { - if let Ok(devs) = host.input_devices() { - for d in devs { - if get_device_name(&d) == target { - return Some(d); - } + && !target.trim().is_empty() + && let Ok(devs) = host.input_devices() { + for d in devs { + if get_device_name(&d) == target { + return Some(d); } } } diff --git a/src/capture/wayland.rs b/src/capture/wayland.rs index e6963b5..8aa5bb0 100644 --- a/src/capture/wayland.rs +++ b/src/capture/wayland.rs @@ -37,7 +37,7 @@ impl WaylandCapture { let select_opts = ashpd::desktop::screencast::SelectSourcesOptions::default() .set_multiple(false) .set_cursor_mode(cursor_mode) - .set_sources(SourceType::Monitor | SourceType::Monitor) + .set_sources(SourceType::Monitor | SourceType::Window) .set_persist_mode(PersistMode::DoNot); proxy.select_sources(&session, select_opts).await.map_err(|e| { diff --git a/src/config.rs b/src/config.rs index 0f8cff3..fccfc00 100644 --- a/src/config.rs +++ b/src/config.rs @@ -110,14 +110,13 @@ impl VrecConfig { pub fn expand_tilde(path: &str) -> PathBuf { let trimmed = path.trim(); - if trimmed.starts_with("~/") { + if let Some(sub) = trimmed.strip_prefix("~/") { if let Some(home) = dirs::home_dir() { - return home.join(&trimmed[2..]); + return home.join(sub); } - } else if trimmed == "~" { - if let Some(home) = dirs::home_dir() { + } else if trimmed == "~" + && let Some(home) = dirs::home_dir() { return home; - } } PathBuf::from(trimmed) } @@ -131,10 +130,9 @@ impl VrecConfig { pub fn load() -> Self { let path = Self::config_path(); - if let Ok(content) = fs::read_to_string(&path) { - if let Ok(cfg) = serde_json::from_str(&content) { + if let Ok(content) = fs::read_to_string(&path) + && let Ok(cfg) = serde_json::from_str(&content) { return cfg; - } } let default_cfg = Self::default(); let _ = default_cfg.save(); diff --git a/src/hyprland_binds.rs b/src/hyprland_binds.rs index fb1af4b..653d16b 100644 --- a/src/hyprland_binds.rs +++ b/src/hyprland_binds.rs @@ -171,8 +171,8 @@ pub fn spawn_hyprland_reload_watcher() { std::thread::spawn(|| { loop { - if let Some(sock_path) = get_hyprland_socket2() { - if let Ok(stream) = UnixStream::connect(&sock_path) { + if let Some(sock_path) = get_hyprland_socket2() + && let Ok(stream) = UnixStream::connect(&sock_path) { let reader = BufReader::new(stream); for line in reader.lines().map_while(Result::ok) { if line.starts_with("configreloaded") { @@ -181,7 +181,6 @@ pub fn spawn_hyprland_reload_watcher() { register_hyprland_binds(&config); } } - } } std::thread::sleep(std::time::Duration::from_secs(3)); } diff --git a/src/overlay_egui.rs b/src/overlay_egui.rs index 8c2f5df..b4f2e7a 100644 --- a/src/overlay_egui.rs +++ b/src/overlay_egui.rs @@ -29,8 +29,8 @@ fn scan_recordings(dir_str: &str) -> Vec { if let Ok(entries) = std::fs::read_dir(&dir) { for entry in entries.flatten() { let path = entry.path(); - if path.is_file() { - if let Some(ext) = path.extension() { + if path.is_file() + && let Some(ext) = path.extension() { let ext_str = ext.to_string_lossy().to_lowercase(); if ext_str == "mp4" || ext_str == "mkv" { let filename = path.file_name().unwrap_or_default().to_string_lossy().to_string(); @@ -45,11 +45,10 @@ fn scan_recordings(dir_str: &str) -> Vec { is_replay, }); } - } } } } - clips.sort_by(|a, b| b.modified.cmp(&a.modified)); + clips.sort_by_key(|b| std::cmp::Reverse(b.modified)); clips } @@ -104,6 +103,12 @@ pub struct VrecOverlayApp { last_clip_scan: Instant, } +impl Default for VrecOverlayApp { + fn default() -> Self { + Self::new() + } +} + impl VrecOverlayApp { pub fn new() -> Self { let config = VrecConfig::load(); @@ -445,8 +450,8 @@ impl eframe::App for VrecOverlayApp { }); // Toast status feedback - if let Some((msg, time)) = &self.status_msg { - if time.elapsed() < Duration::from_secs(3) { + if let Some((msg, time)) = &self.status_msg + && time.elapsed() < Duration::from_secs(3) { ui.add_space(6.0); egui::Frame::NONE .fill(Color32::from_rgba_unmultiplied(16, 185, 129, 25)) @@ -461,7 +466,6 @@ impl eframe::App for VrecOverlayApp { .strong(), ); }); - } } ui.add_space(10.0);