enforce stricter lints, drop discarded results properly

This commit is contained in:
2026-09-21 00:40:51 +03:00
parent 95d168d5d8
commit 1332600148
12 changed files with 204 additions and 171 deletions
+77 -75
View File
@@ -158,7 +158,7 @@ pub struct HotkeyRegistrationResult {
fn register_hotkeys(app: &AppHandle, cfg: &Config) -> HotkeyRegistrationResult {
let gs = app.global_shortcut();
let _ = gs.unregister_all();
drop(gs.unregister_all());
let start_ok = cfg
.hotkeys
@@ -258,10 +258,10 @@ async fn download_update(
let dest = updates::pending_update_path(&state.app_dir);
let app_handle = app.clone();
updates::download_to(&url, &dest, move |downloaded, total| {
let _ = app_handle.emit(
drop(app_handle.emit(
"update-download-progress",
UpdateDownloadProgress { downloaded, total },
);
));
})
.await
.map_err(|e| format!("{e:#}"))
@@ -294,10 +294,10 @@ async fn download_ffmpeg(app: AppHandle, state: State<'_, AppState>) -> Result<(
let app_dir = state.app_dir.clone();
let app_handle = app.clone();
bootstrap::download(&app_dir, move |downloaded, total| {
let _ = app_handle.emit(
drop(app_handle.emit(
"ffmpeg-progress",
DownloadProgress { downloaded, total },
);
));
})
.await
.map_err(|e| format!("{e:#}"))
@@ -326,26 +326,26 @@ fn clear_temp_segments(app_dir: &Path) {
|| (name.starts_with("audio-") && name.ends_with(".pcm"))
|| (name.starts_with("preview-palette-") && name.ends_with(".png"))
{
let _ = std::fs::remove_file(entry.path());
drop(std::fs::remove_file(entry.path()));
}
}
}
}
let _ = std::fs::remove_file(temp.join("recording.mp4"));
let _ = std::fs::remove_file(temp.join("video-concat.mp4"));
let _ = std::fs::remove_file(temp.join("audio-concat.pcm"));
drop(std::fs::remove_file(temp.join("recording.mp4")));
drop(std::fs::remove_file(temp.join("video-concat.mp4")));
drop(std::fs::remove_file(temp.join("audio-concat.pcm")));
let thumbs = temp.join("thumbs");
if thumbs.is_dir() {
let _ = std::fs::remove_dir_all(&thumbs);
drop(std::fs::remove_dir_all(&thumbs));
}
let _ = std::fs::remove_file(temp.join("preview.png"));
let _ = std::fs::remove_file(temp.join("raw-preview.png"));
drop(std::fs::remove_file(temp.join("preview.png")));
drop(std::fs::remove_file(temp.join("raw-preview.png")));
}
/// Pad or trim a raw f32le PCM file so its duration matches `target_secs`.
fn adjust_audio_length(path: &Path, sample_rate: u32, channels: u16, target_secs: f64) -> Result<()> {
use std::io::Write;
let bytes_per_sec = sample_rate as f64 * channels as f64 * 4.0;
let bytes_per_sec = f64::from(sample_rate) * f64::from(channels) * 4.0;
let target_bytes = (target_secs * bytes_per_sec).round() as u64;
let current_bytes = std::fs::metadata(path)?.len();
if current_bytes == target_bytes {
@@ -376,7 +376,7 @@ fn adjust_audio_length(path: &Path, sample_rate: u32, channels: u16, target_secs
/// form held it all in a Vec before rewriting.
fn pad_audio_head(path: &Path, sample_rate: u32, channels: u16, head_secs: f64) -> Result<()> {
use std::io::Write;
let bytes_per_sec = sample_rate as f64 * channels as f64 * 4.0;
let bytes_per_sec = f64::from(sample_rate) * f64::from(channels) * 4.0;
let pad_bytes = (head_secs * bytes_per_sec).round() as u64;
if pad_bytes == 0 {
return Ok(());
@@ -404,7 +404,7 @@ fn pad_audio_head(path: &Path, sample_rate: u32, channels: u16, head_secs: f64)
// (e.g. a handle still holds the file on Windows).
if std::fs::rename(&temp, path).is_err() {
std::fs::copy(&temp, path)?;
let _ = std::fs::remove_file(&temp);
drop(std::fs::remove_file(&temp));
}
tracing::debug!(
"padded audio head with {:.1}ms ({} bytes) of silence",
@@ -415,7 +415,7 @@ fn pad_audio_head(path: &Path, sample_rate: u32, channels: u16, head_secs: f64)
fn set_overlay_clickthrough(app: &AppHandle, enabled: bool) {
if let Some(win) = app.get_webview_window("overlay") {
let _ = win.set_ignore_cursor_events(enabled);
drop(win.set_ignore_cursor_events(enabled));
}
}
@@ -431,7 +431,7 @@ fn try_start_audio(
Ok(s) => Some(s),
Err(e) => {
tracing::warn!("audio capture failed: {e:#}");
let _ = app.emit("audio-failed", e.to_string());
drop(app.emit("audio-failed", e.to_string()));
None
}
}
@@ -473,11 +473,11 @@ fn watch_audio_death(app: AppHandle, died: Arc<AtomicBool>) {
if let Some(session) = take {
// Drain the dead thread so its handle doesn't leak. The pcm
// it already wrote stays in place for stop_capture to mux.
let _ = session.stop();
let _ = app.emit(
drop(session.stop());
drop(app.emit(
"audio-failed",
"audio device lost - endpoint changed or was unplugged".to_string(),
);
));
}
return;
}
@@ -695,7 +695,7 @@ fn restart_audio_capture(
*lock(&state.audio) = audio_recovered;
if recovered {
let _ = app.emit("audio-recovered", ());
drop(app.emit("audio-recovered", ()));
}
Ok(())
}
@@ -760,7 +760,7 @@ fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result<RecordedCl
encode::concat_segments(&ffmpeg, &ss.segments, &vc)
.map_err(|e| format!("concat: {e:#}"))?;
for seg in &ss.segments {
let _ = std::fs::remove_file(seg);
drop(std::fs::remove_file(seg));
}
vc
};
@@ -810,17 +810,17 @@ fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result<RecordedCl
)
.map_err(|e| format!("mux: {e:#}"))?;
if video_concat != final_path {
let _ = std::fs::remove_file(&video_concat);
drop(std::fs::remove_file(&video_concat));
}
let _ = std::fs::remove_file(&audio_concat);
drop(std::fs::remove_file(&audio_concat));
for ap in &ss.audio_segments {
let _ = std::fs::remove_file(ap);
drop(std::fs::remove_file(ap));
}
} else if video_concat != final_path {
std::fs::rename(&video_concat, &final_path)
.or_else(|_| std::fs::copy(&video_concat, &final_path).map(|_| ()))
.map_err(|e| format!("finalizing: {e:#}"))?;
let _ = std::fs::remove_file(&video_concat);
drop(std::fs::remove_file(&video_concat));
}
let clip = RecordedClip {
@@ -1180,8 +1180,8 @@ fn start_overlay_clickthrough_poll(
None => continue,
};
let dpi = unsafe { GetDpiForWindow(HWND(raw.0 as *mut _)) };
let scale = if dpi > 0 { dpi as f64 / 96.0 } else { 1.0 };
let dpi = unsafe { GetDpiForWindow(HWND(raw.0 as *mut std::ffi::c_void)) };
let scale = if dpi > 0 { f64::from(dpi) / 96.0 } else { 1.0 };
let border = (OVERLAY_BORDER_LOGICAL_PX * scale).round() as i32;
let titlebar = (OVERLAY_TITLEBAR_LOGICAL_PX * scale).round() as i32;
@@ -1196,7 +1196,7 @@ fn start_overlay_clickthrough_poll(
&& pt.y < inner_bottom;
if last_inner != Some(in_inner) {
let _ = overlay.set_ignore_cursor_events(in_inner);
drop(overlay.set_ignore_cursor_events(in_inner));
last_inner = Some(in_inner);
}
std::thread::sleep(Duration::from_millis(80));
@@ -1210,7 +1210,7 @@ fn mark_overlay_excluded_from_capture(win: &tauri::WebviewWindow) -> Result<(),
SetWindowDisplayAffinity, WDA_EXCLUDEFROMCAPTURE,
};
let raw = win.hwnd().map_err(|e| format!("hwnd: {e}"))?;
let hwnd = HWND(raw.0 as *mut _);
let hwnd = HWND(raw.0 as *mut std::ffi::c_void);
unsafe {
SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE)
.map_err(|e| format!("SetWindowDisplayAffinity: {e}"))?;
@@ -1224,7 +1224,7 @@ fn show_overlay(app: AppHandle) -> Result<(), String> {
.get_webview_window("overlay")
.ok_or_else(|| "overlay window not found".to_string())?;
win.show().map_err(|e| format!("showing overlay: {e:#}"))?;
let _ = mark_overlay_excluded_from_capture(&win);
drop(mark_overlay_excluded_from_capture(&win));
// Wake the click-through poll thread out of its parked state.
{
@@ -1245,7 +1245,7 @@ fn show_overlay(app: AppHandle) -> Result<(), String> {
let center = POINT { x: (vl + vr) / 2, y: (vt + vb) / 2 };
let hmon = unsafe { MonitorFromPoint(center, MONITOR_DEFAULTTONULL) };
if hmon.0.is_null() {
let hwnd = HWND(raw.0 as *mut _);
let hwnd = HWND(raw.0 as *mut std::ffi::c_void);
let primary = unsafe { MonitorFromPoint(POINT { x: 0, y: 0 }, MONITOR_DEFAULTTOPRIMARY) };
let mut mi = MONITORINFO { cbSize: std::mem::size_of::<MONITORINFO>() as u32, ..Default::default() };
if unsafe { GetMonitorInfoW(primary, &mut mi) }.as_bool() {
@@ -1254,7 +1254,9 @@ fn show_overlay(app: AppHandle) -> Result<(), String> {
let h = vb - vt;
let cx = (work.left + work.right) / 2 - w / 2;
let cy = (work.top + work.bottom) / 2 - h / 2;
let _ = unsafe { SetWindowPos(hwnd, Some(HWND_TOP), cx, cy, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE) };
drop(
unsafe { SetWindowPos(hwnd, Some(HWND_TOP), cx, cy, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE) },
);
}
}
}
@@ -1269,7 +1271,7 @@ fn hide_overlay(app: AppHandle) -> Result<(), String> {
.ok_or_else(|| "overlay window not found".to_string())?;
// Reset click-through so the next show starts from a known state, and park
// the poll thread until show_overlay wakes it again.
let _ = win.set_ignore_cursor_events(false);
drop(win.set_ignore_cursor_events(false));
{
let st = app.state::<AppState>();
let (lock, cvar) = &*st.overlay_poll_live;
@@ -1286,7 +1288,7 @@ fn set_overlay_size(app: AppHandle, state: State<'_, AppState>, width: u32, heig
.get_webview_window("overlay")
.ok_or_else(|| "overlay window not found".to_string())?;
let ratio = lock(&state.overlay_aspect_ratio);
let (w, mut h) = (width as f64, height as f64);
let (w, mut h) = (f64::from(width), f64::from(height));
if let Some(r) = *ratio {
h = w / r;
}
@@ -1307,8 +1309,8 @@ fn set_overlay_aspect(app: AppHandle, state: State<'_, AppState>, ratio: Option<
.ok_or_else(|| "overlay window not found".to_string())?;
let scale = win.scale_factor().unwrap_or(1.0);
let sz = win.inner_size().map_err(|e| format!("getting window size: {e:#}"))?;
let cur_w = sz.width as f64 / scale;
let cur_h = sz.height as f64 / scale;
let cur_w = f64::from(sz.width) / scale;
let cur_h = f64::from(sz.height) / scale;
let target_h = cur_w / r;
if (target_h - cur_h).abs() > 1.0 {
use tauri::{LogicalSize, Size};
@@ -1337,8 +1339,8 @@ fn enforce_overlay_aspect(app: AppHandle, state: State<'_, AppState>) -> Result<
.ok_or_else(|| "overlay window not found".to_string())?;
let scale = win.scale_factor().unwrap_or(1.0);
let sz = win.inner_size().map_err(|e| format!("getting window size: {e:#}"))?;
let cur_w = sz.width as f64 / scale;
let cur_h = sz.height as f64 / scale;
let cur_w = f64::from(sz.width) / scale;
let cur_h = f64::from(sz.height) / scale;
let target_h = (cur_w / ratio).round();
if (target_h - cur_h).abs() <= 2.0 {
return Ok(()); // already correct
@@ -1347,12 +1349,12 @@ 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 raw = win.hwnd().map_err(|e| format!("hwnd: {e}"))?;
let hwnd = HWND(raw.0 as *mut _);
let hwnd = HWND(raw.0 as *mut std::ffi::c_void);
// Compute outer size including borders
let border = (OVERLAY_BORDER_LOGICAL_PX * scale).round() as i32;
let titlebar = (OVERLAY_TITLEBAR_LOGICAL_PX * scale).round() as i32;
let outer_w = (sz.width as i32).max(2);
let outer_h = (target_h * scale + titlebar as f64 + border as f64 * 2.0).round() as i32;
let outer_w = sz.width.cast_signed().max(2);
let outer_h = (target_h * scale + f64::from(titlebar) + f64::from(border) * 2.0).round() as i32;
unsafe {
SetWindowPos(hwnd, Some(HWND_TOP), 0, 0, outer_w, outer_h,
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE)
@@ -1398,25 +1400,25 @@ fn open_window_picker(
picker
.set_position(Position::Physical(PhysicalPosition::new(0, 0)))
.map_err(|e| format!("setting picker position: {e:#}"))?;
let _ = picker.set_ignore_cursor_events(false);
let _ = picker.set_always_on_top(true);
drop(picker.set_ignore_cursor_events(false));
drop(picker.set_always_on_top(true));
picker.show().map_err(|e| format!("showing picker: {e:#}"))?;
if let Ok(h) = picker.hwnd() {
use windows::Win32::Foundation::{HWND, RECT};
use windows::Win32::Graphics::Dwm::{DwmGetWindowAttribute, DWMWA_EXTENDED_FRAME_BOUNDS};
use windows::Win32::UI::WindowsAndMessaging::GetWindowRect;
let hwnd = HWND(h.0 as *mut _);
let hwnd = HWND(h.0 as *mut std::ffi::c_void);
let mut gr = RECT::default();
let _ = unsafe { GetWindowRect(hwnd, &mut gr) };
drop(unsafe { GetWindowRect(hwnd, &mut gr) });
let mut dr = RECT::default();
let _ = unsafe {
drop(unsafe {
DwmGetWindowAttribute(
hwnd,
DWMWA_EXTENDED_FRAME_BOUNDS,
&mut dr as *mut RECT as *mut std::ffi::c_void,
&raw mut dr as *mut RECT as *mut std::ffi::c_void,
std::mem::size_of::<RECT>() as u32,
)
};
});
tracing::debug!(
"picker window: GetWindowRect=({},{},{},{}) DwmBounds=({},{},{},{})",
gr.left, gr.top, gr.right, gr.bottom,
@@ -1443,7 +1445,7 @@ fn close_window_picker(
session.stop();
}
if let Some(picker) = app.get_webview_window("picker") {
let _ = picker.hide();
drop(picker.hide());
}
Ok(())
}
@@ -1452,7 +1454,7 @@ fn visible_window_bounds(hwnd_raw: isize) -> Option<(i32, i32, i32, i32)> {
use windows::Win32::Foundation::{HWND, RECT};
use windows::Win32::Graphics::Dwm::{DwmGetWindowAttribute, DWMWA_EXTENDED_FRAME_BOUNDS};
use windows::Win32::UI::WindowsAndMessaging::GetWindowRect;
let hwnd = HWND(hwnd_raw as *mut _);
let hwnd = HWND(hwnd_raw as *mut std::ffi::c_void);
let mut dwm = RECT::default();
if unsafe {
DwmGetWindowAttribute(
@@ -1481,7 +1483,7 @@ fn dwm_insets(hwnd_raw: isize) -> (i32, i32, i32, i32) {
use windows::Win32::Graphics::Dwm::{DwmGetWindowAttribute, DWMWA_EXTENDED_FRAME_BOUNDS};
use windows::Win32::UI::WindowsAndMessaging::GetWindowRect;
let hwnd = HWND(hwnd_raw as *mut _);
let hwnd = HWND(hwnd_raw as *mut std::ffi::c_void);
let mut outer = RECT::default();
if unsafe { GetWindowRect(hwnd, &mut outer) }.is_err() {
return (0, 0, 0, 0);
@@ -1528,7 +1530,7 @@ fn scale_factor_at_point(x: i32, y: i32) -> f64 {
)
};
if hr.is_ok() && dpi_x > 0 {
dpi_x as f64 / 96.0
f64::from(dpi_x) / 96.0
} else {
1.0
}
@@ -1547,8 +1549,8 @@ fn set_overlay_to_window(
.ok_or_else(|| "overlay window not found".to_string())?;
// Use the target monitor's scale factor, not the overlay's current one,
// so border/titlebar compensation is correct when snapping across monitors.
let cx = x.saturating_add(width as i32 / 2);
let cy = y.saturating_add(height as i32 / 2);
let cx = x.saturating_add(width.cast_signed() / 2);
let cy = y.saturating_add(height.cast_signed() / 2);
let scale = scale_factor_at_point(cx, cy);
let border_phys = (OVERLAY_BORDER_LOGICAL_PX * scale).round() as i32;
let titlebar_phys = (OVERLAY_TITLEBAR_LOGICAL_PX * scale).round() as i32;
@@ -1557,8 +1559,8 @@ fn set_overlay_to_window(
// The capture region is inside the border + below the titlebar.
let visible_left = x - border_phys;
let visible_top = y - border_phys - titlebar_phys;
let visible_w = width as i32 + border_phys * 2;
let visible_h = height as i32 + border_phys * 2 + titlebar_phys;
let visible_w = width.cast_signed() + border_phys * 2;
let visible_h = height.cast_signed() + border_phys * 2 + titlebar_phys;
// Compensate for the invisible DWM border that Windows adds around
// top-level windows (Tauri's set_position sets the outer rect, but the
@@ -1570,8 +1572,8 @@ fn set_overlay_to_window(
let outer_x = visible_left - li;
let outer_y = visible_top - ti;
let outer_w = (visible_w + li + ri).max(2) as u32;
let outer_h = (visible_h + ti + bi).max(2) as u32;
let outer_w = (visible_w + li + ri).max(2).cast_unsigned();
let outer_h = (visible_h + ti + bi).max(2).cast_unsigned();
// Bypass Tauri's set_position/set_size which adds extra pixels for
// some unknown reason. Use Win32 SetWindowPos with explicit outer rect.
@@ -1580,15 +1582,15 @@ fn set_overlay_to_window(
use windows::Win32::UI::WindowsAndMessaging::{
SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOZORDER,
};
let hwnd = HWND(raw.0 as *mut _);
let hwnd = HWND(raw.0 as *mut std::ffi::c_void);
unsafe {
SetWindowPos(
hwnd,
Some(HWND_TOP),
outer_x,
outer_y,
outer_w as i32,
outer_h as i32,
outer_w.cast_signed(),
outer_h.cast_signed(),
SWP_NOACTIVATE | SWP_NOZORDER,
)
}
@@ -1617,8 +1619,8 @@ fn get_overlay_rect(app: AppHandle) -> Result<CaptureRect, String> {
let visible_w = vr - vl;
let visible_h = vb - vt;
let width = (visible_w - inset_sides * 2).max(2) as u32;
let height = (visible_h - inset_top - inset_sides).max(2) as u32;
let width = (visible_w - inset_sides * 2).max(2).cast_unsigned();
let height = (visible_h - inset_top - inset_sides).max(2).cast_unsigned();
let width = (width / 2) * 2;
let height = (height / 2) * 2;
@@ -1746,7 +1748,7 @@ fn diagnostics_info(state: State<'_, AppState>) -> DiagnosticsInfo {
fn open_log_dir(state: State<'_, AppState>) -> Result<(), String> {
use std::os::windows::process::CommandExt;
let log_dir = state.app_dir.join("logs");
let _ = std::fs::create_dir_all(&log_dir);
drop(std::fs::create_dir_all(&log_dir));
std::process::Command::new("explorer.exe")
.raw_arg(log_dir.to_string_lossy().to_string())
.spawn()
@@ -1820,14 +1822,14 @@ async fn export(app: AppHandle, state: State<'_, AppState>, request: ExportReque
(0, 0),
)
};
let scale = clip.width as f64 / src_w as f64;
let scale = f64::from(clip.width) / f64::from(src_w);
let transformed_clicks: Vec<clicks::Click> = clip
.clicks
.iter()
.map(|c| clicks::Click {
time_secs: c.time_secs,
x: (((c.x - src_origin.0) as f64) * scale).round() as i32,
y: (((c.y - src_origin.1) as f64) * scale).round() as i32,
x: (f64::from(c.x - src_origin.0) * scale).round() as i32,
y: (f64::from(c.y - src_origin.1) * scale).round() as i32,
button: c.button,
})
.collect();
@@ -1867,14 +1869,14 @@ async fn export(app: AppHandle, state: State<'_, AppState>, request: ExportReque
// so the progress bar accumulates across retry attempts.
std::thread::spawn(move || {
while let Ok(progress) = rx.recv() {
let _ = app_handle.emit(
drop(app_handle.emit(
"encode-progress",
encode::EncodeProgress {
pass: progress.pass,
total_passes: progress.total_passes,
percent: progress.percent,
},
);
));
}
});
@@ -1911,7 +1913,7 @@ pub fn run() {
clear_temp_segments(&app_dir);
let log_dir = app_dir.join("logs");
let _ = std::fs::create_dir_all(&log_dir);
drop(std::fs::create_dir_all(&log_dir));
let file_appender = tracing_appender::rolling::daily(&log_dir, "bytesize.log");
let (file_writer, _log_guard) = tracing_appender::non_blocking(file_appender);
@@ -1923,7 +1925,7 @@ pub fn run() {
#[cfg(debug_assertions)]
let registry = registry.with(tracing_subscriber::fmt::layer().with_writer(std::io::stdout));
#[cfg(test)]
let _ = registry.try_init();
drop(registry.try_init());
#[cfg(not(test))]
registry.init();
@@ -2006,7 +2008,7 @@ pub fn run() {
None
};
if let Some(k) = kind {
let _ = app.emit("hotkey", k);
drop(app.emit("hotkey", k));
}
})
.build(),
@@ -2018,7 +2020,7 @@ pub fn run() {
let cfg = lock(&st.config).clone();
(cfg.updates.check_on_launch, cfg)
};
let _ = register_hotkeys(app.handle(), &cfg);
drop(register_hotkeys(app.handle(), &cfg));
{
let st = app.state::<AppState>();
start_overlay_clickthrough_poll(
@@ -2039,7 +2041,7 @@ pub fn run() {
match updates::check_for_update().await {
Ok(Some(info)) => {
tracing::info!(version = info.version, "update available");
let _ = handle.emit("update-available", &info);
drop(handle.emit("update-available", &info));
}
Ok(None) => tracing::debug!("no update available"),
Err(e) => tracing::warn!("update check failed: {e:#}"),