case-insensitive extensions and explicit else arms

This commit is contained in:
2026-09-21 01:30:12 +03:00
parent 9e23a5b7d3
commit c7a4721e7d
4 changed files with 51 additions and 30 deletions
+2
View File
@@ -337,6 +337,8 @@ fn find_ffmpeg_in(dir: &Path) -> Option<PathBuf> {
return Some(p);
}
}
// Anything else is neither a directory nor a named file, so there is
// nothing to look at inside it.
}
None
}
+22 -13
View File
@@ -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.
_ => {}
}
}
}
+23 -14
View File
@@ -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<RecordedCl
.or_else(|_| std::fs::copy(&video_concat, &final_path).map(|_| ()))
.map_err(|e| format!("finalizing: {e:#}"))?;
drop(std::fs::remove_file(&video_concat));
} else {
// No audio and a single segment: the concat output already sits at
// final_path, so there is nothing left to move.
}
let clip = RecordedClip {
@@ -1226,14 +1240,10 @@ fn start_overlay_clickthrough_poll(
if unsafe { GetCursorPos(&raw mut pt) }.is_err() {
continue;
}
let raw = match overlay.hwnd() {
Ok(h) => 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")
+4 -3
View File
@@ -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<isize>) -> 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 =