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
+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")