diff --git a/src-tauri/src/bootstrap.rs b/src-tauri/src/bootstrap.rs index 2460127..86de621 100644 --- a/src-tauri/src/bootstrap.rs +++ b/src-tauri/src/bootstrap.rs @@ -337,6 +337,8 @@ fn find_ffmpeg_in(dir: &Path) -> Option { return Some(p); } } + // Anything else is neither a directory nor a named file, so there is + // nothing to look at inside it. } None } diff --git a/src-tauri/src/encode.rs b/src-tauri/src/encode.rs index 85ba57d..7ead391 100644 --- a/src-tauri/src/encode.rs +++ b/src-tauri/src/encode.rs @@ -994,7 +994,12 @@ fn clean_stale_palettes(dir: &Path) { if let Ok(entries) = std::fs::read_dir(dir) { for entry in entries.flatten() { if let Some(name) = entry.file_name().to_str() { - if name.starts_with("preview-palette-") && name.ends_with(".png") { + // Case-insensitive for the same reason as the temp sweep: these + // are the app's own files, but Windows keeps the case it was given. + let is_png = Path::new(name) + .extension() + .is_some_and(|e| e.eq_ignore_ascii_case("png")); + if name.starts_with("preview-palette-") && is_png { drop(std::fs::remove_file(entry.path())); } } @@ -1249,19 +1254,23 @@ fn run_impl( let mut last_out_time_us: f64 = 0.0; for line in reader.lines().map_while(Result::ok) { if let Some((key, value)) = parse_progress_kv(&line) { - if key == "out_time_us" { - last_out_time_us = value; - } else if key == "progress" { - let percent = (last_out_time_us / encode_dur_us * 100.0).clamp(0.0, 100.0); - if let Some(ref sender) = tx { - // A dropped receiver means the frontend is gone; - // the encode keeps running either way. - let _ = sender.send(EncodeProgress { - pass, - total_passes, - percent, - }); + match key { + "out_time_us" => last_out_time_us = value, + "progress" => { + let percent = + (last_out_time_us / encode_dur_us * 100.0).clamp(0.0, 100.0); + if let Some(ref sender) = tx { + // A dropped receiver means the frontend is gone; + // the encode keeps running either way. + let _ = sender.send(EncodeProgress { + pass, + total_passes, + percent, + }); + } } + // frame=, fps=, bitrate= and friends are not needed. + _ => {} } } } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 22faf05..f792882 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -333,15 +333,26 @@ fn audio_segment_path(app_dir: &Path, idx: usize) -> PathBuf { /// raw-preview.png from the previous clip, and deleting them under it made the /// asset protocol log "file does not exist" and briefly broke the preview. /// Startup and exit sweep everything. +/// Case-insensitive extension test, for the temp sweeps: Windows file names are +/// case-preserving, so `ends_with(".mp4")` would miss `SEGMENT-001.MP4`. +fn has_ext(name: &str, ext: &str) -> bool { + Path::new(name) + .extension() + .is_some_and(|e| e.eq_ignore_ascii_case(ext)) +} + fn clear_temp_segments(app_dir: &Path, keep_previews: bool) { let temp = temp_dir(app_dir); if let Ok(entries) = std::fs::read_dir(&temp) { for entry in entries.flatten() { if let Some(name) = entry.file_name().to_str() { - if (name.starts_with("segment-") && name.ends_with(".mp4")) - || (name.starts_with("audio-") && name.ends_with(".pcm")) - || name.ends_with(".pcm.padtmp") - || (name.starts_with("preview-palette-") && name.ends_with(".png")) + // The padtmp files carry a double extension, so they are matched + // on the whole name rather than through Path::extension. + let padtmp = name.to_ascii_lowercase().ends_with(".pcm.padtmp"); + if (name.starts_with("segment-") && has_ext(name, "mp4")) + || (name.starts_with("audio-") && has_ext(name, "pcm")) + || (name.starts_with("preview-palette-") && has_ext(name, "png")) + || padtmp { drop(std::fs::remove_file(entry.path())); } @@ -843,6 +854,9 @@ fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result h, - Err(_) => continue, - }; + let Ok(raw) = overlay.hwnd() else { continue }; - let (vl, vt, vr, vb) = match visible_window_bounds(raw.0 as isize) { - Some(b) => b, - None => continue, + let Some((vl, vt, vr, vb)) = visible_window_bounds(raw.0 as isize) else { + continue; }; // SAFETY: `raw` is the overlay's own live HWND from Tauri. @@ -1405,9 +1415,8 @@ fn enforce_overlay_aspect(app: AppHandle, state: State<'_, AppState>) -> Result< use windows::Win32::Foundation::HWND; use windows::Win32::UI::WindowsAndMessaging::{SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOZORDER}; - let ratio = match *lock(&state.overlay_aspect_ratio) { - Some(r) => r, - None => return Ok(()), + let Some(ratio) = *lock(&state.overlay_aspect_ratio) else { + return Ok(()); }; let win = app .get_webview_window("overlay") diff --git a/src-tauri/src/window_picker.rs b/src-tauri/src/window_picker.rs index 31a55d0..794dcda 100644 --- a/src-tauri/src/window_picker.rs +++ b/src-tauri/src/window_picker.rs @@ -137,9 +137,8 @@ unsafe extern "system" fn enum_at_point(hwnd: HWND, lparam: LPARAM) -> BOOL { return BOOL(1); } // SAFETY: `hwnd` is the live handle described above. - let rect = match unsafe { visible_window_rect(hwnd) } { - Some(r) => r, - None => return BOOL(1), + let Some(rect) = (unsafe { visible_window_rect(hwnd) }) else { + return BOOL(1); }; if ctx.point.x < rect.left || ctx.point.x >= rect.right @@ -223,6 +222,8 @@ pub(crate) fn start(app: AppHandle, exclude_hwnds: Vec) -> PickerSession } else if last_hwnd != 0 { tracing::info!("picker hover: no target found at ({}, {})", pt.x, pt.y); last_hwnd = 0; + } else { + // Still hovering the same window, so the frame is already drawn. } let pressed =