chore(code-quality): clean clippy lints and improve Wayland source selection
This commit is contained in:
parent
c6787bd7ee
commit
3047809224
7 changed files with 31 additions and 34 deletions
|
|
@ -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<dyn std::error::Error + Send + Sync>> {
|
|||
};
|
||||
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<dyn std::error::Error + Send + Sync>> {
|
|||
0
|
||||
};
|
||||
prepared.push((time_us, rebased));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -275,12 +275,11 @@ impl AudioCapture {
|
|||
let find_mic_device = || -> Option<cpal::Device> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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| {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ fn scan_recordings(dir_str: &str) -> Vec<VideoClipInfo> {
|
|||
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<VideoClipInfo> {
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue