tighten visibility and clear the remaining mechanical lint noise
This commit is contained in:
+46
-51
@@ -51,8 +51,8 @@ pub struct AppState {
|
||||
pub overlay_aspect_ratio: Mutex<Option<f64>>,
|
||||
/// (active flag, condvar) so the overlay click-through poll thread can park
|
||||
/// itself when no overlay is on screen instead of waking every 80ms.
|
||||
/// show_overlay/hide_overlay flip the flag and notify.
|
||||
pub overlay_poll_live: Arc<(std::sync::Mutex<bool>, std::sync::Condvar)>,
|
||||
/// `show_overlay/hide_overlay` flip the flag and notify.
|
||||
pub overlay_poll_live: Arc<(Mutex<bool>, std::sync::Condvar)>,
|
||||
}
|
||||
|
||||
pub struct SessionState {
|
||||
@@ -310,11 +310,11 @@ pub struct StartCaptureRequest {
|
||||
}
|
||||
|
||||
fn segment_path(app_dir: &Path, idx: usize) -> PathBuf {
|
||||
temp_dir(app_dir).join(format!("segment-{:03}.mp4", idx))
|
||||
temp_dir(app_dir).join(format!("segment-{idx:03}.mp4"))
|
||||
}
|
||||
|
||||
fn audio_segment_path(app_dir: &Path, idx: usize) -> PathBuf {
|
||||
temp_dir(app_dir).join(format!("audio-{:03}.pcm", idx))
|
||||
temp_dir(app_dir).join(format!("audio-{idx:03}.pcm"))
|
||||
}
|
||||
|
||||
fn clear_temp_segments(app_dir: &Path) {
|
||||
@@ -449,7 +449,7 @@ fn start_click_recorder(enabled: bool) -> Option<clicks::ClickRecorder> {
|
||||
/// output switched, WASAPI invalidated the client). The capture thread sets
|
||||
/// its `died` flag on such an exit; this poller emits `audio-failed` so the
|
||||
/// existing retry UI in Main.svelte can recover mid-record instead of the
|
||||
/// session slot silently holding a dead thread until stop_capture.
|
||||
/// session slot silently holding a dead thread until `stop_capture`.
|
||||
fn watch_audio_death(app: AppHandle, died: Arc<AtomicBool>) {
|
||||
std::thread::spawn(move || {
|
||||
use std::time::Duration;
|
||||
@@ -531,8 +531,7 @@ fn start_capture(
|
||||
|
||||
let (a_sr, a_ch) = audio_session
|
||||
.as_ref()
|
||||
.map(|s| (Some(s.sample_rate), Some(s.channels)))
|
||||
.unwrap_or((None, None));
|
||||
.map_or((None, None), |s| (Some(s.sample_rate), Some(s.channels)));
|
||||
|
||||
let session_state = SessionState {
|
||||
segments: Vec::new(),
|
||||
@@ -571,7 +570,7 @@ fn pause_capture(state: State<'_, AppState>) -> Result<(), String> {
|
||||
.take()
|
||||
.ok_or_else(|| "no capture in progress".to_string())?;
|
||||
let elapsed = session.started_at.elapsed().as_secs_f64();
|
||||
let frames = session.frame_counter.load(std::sync::atomic::Ordering::Relaxed);
|
||||
let frames = session.frame_counter.load(Ordering::Relaxed);
|
||||
let pipe_fps = session.pipe_fps;
|
||||
let raw_path = session.stop().map_err(|e| format!("{e:#}"))?;
|
||||
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
||||
@@ -586,7 +585,7 @@ fn pause_capture(state: State<'_, AppState>) -> Result<(), String> {
|
||||
|
||||
let new_clicks: Vec<clicks::Click> = lock(&state.click_recorder)
|
||||
.take()
|
||||
.map(|r| r.stop())
|
||||
.map(clicks::ClickRecorder::stop)
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut ss = lock(&state.session);
|
||||
@@ -711,7 +710,7 @@ fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result<RecordedCl
|
||||
let live = lock(&state.capture).take();
|
||||
if let Some(session) = live {
|
||||
let elapsed = session.started_at.elapsed().as_secs_f64();
|
||||
let frames = session.frame_counter.load(std::sync::atomic::Ordering::Relaxed);
|
||||
let frames = session.frame_counter.load(Ordering::Relaxed);
|
||||
let pipe_fps = session.pipe_fps;
|
||||
let raw_path = session.stop().map_err(|e| format!("{e:#}"))?;
|
||||
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
||||
@@ -732,7 +731,7 @@ fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result<RecordedCl
|
||||
|
||||
let live_clicks = lock(&state.click_recorder)
|
||||
.take()
|
||||
.map(|r| r.stop())
|
||||
.map(clicks::ClickRecorder::stop)
|
||||
.unwrap_or_default();
|
||||
let offset = *ss.segment_start_offsets.last().unwrap_or(&0.0);
|
||||
for c in live_clicks {
|
||||
@@ -978,7 +977,7 @@ fn estimate_gif_params(request: PreviewRequest) -> GifEstimate {
|
||||
GifEstimate { width: w, fps, height, dims_label }
|
||||
}
|
||||
|
||||
/// Return estimates for a grid of target_bytes values so the frontend can
|
||||
/// Return estimates for a grid of `target_bytes` values so the frontend can
|
||||
/// interpolate on slider drag without an IPC per debounce tick. The grid is
|
||||
/// geometric from 100KB to 200MB.
|
||||
#[tauri::command]
|
||||
@@ -1125,7 +1124,7 @@ fn cleanup_temp_on_exit(app: &AppHandle) {
|
||||
fn start_overlay_clickthrough_poll(
|
||||
app: AppHandle,
|
||||
shutdown: Arc<AtomicBool>,
|
||||
live: Arc<(std::sync::Mutex<bool>, std::sync::Condvar)>,
|
||||
live: Arc<(Mutex<bool>, std::sync::Condvar)>,
|
||||
) {
|
||||
use std::time::Duration;
|
||||
use windows::Win32::Foundation::{HWND, POINT};
|
||||
@@ -1141,11 +1140,11 @@ fn start_overlay_clickthrough_poll(
|
||||
// flips the flag and notifies.
|
||||
{
|
||||
let (lock, cvar) = &*live;
|
||||
let mut active = lock.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut active = lock.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
while !*active && !shutdown.load(Ordering::Relaxed) {
|
||||
let (g, _timeout) = cvar
|
||||
.wait_timeout(active, Duration::from_secs(1))
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
active = g;
|
||||
}
|
||||
}
|
||||
@@ -1167,7 +1166,7 @@ fn start_overlay_clickthrough_poll(
|
||||
}
|
||||
|
||||
let mut pt = POINT::default();
|
||||
if unsafe { GetCursorPos(&mut pt) }.is_err() {
|
||||
if unsafe { GetCursorPos(&raw mut pt) }.is_err() {
|
||||
continue;
|
||||
}
|
||||
let raw = match overlay.hwnd() {
|
||||
@@ -1180,7 +1179,7 @@ fn start_overlay_clickthrough_poll(
|
||||
None => continue,
|
||||
};
|
||||
|
||||
let dpi = unsafe { GetDpiForWindow(HWND(raw.0 as *mut std::ffi::c_void)) };
|
||||
let dpi = unsafe { GetDpiForWindow(HWND(raw.0.cast::<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;
|
||||
@@ -1210,7 +1209,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 std::ffi::c_void);
|
||||
let hwnd = HWND(raw.0.cast::<std::ffi::c_void>());
|
||||
unsafe {
|
||||
SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE)
|
||||
.map_err(|e| format!("SetWindowDisplayAffinity: {e}"))?;
|
||||
@@ -1230,7 +1229,7 @@ fn show_overlay(app: AppHandle) -> Result<(), String> {
|
||||
{
|
||||
let st = app.state::<AppState>();
|
||||
let (lock, cvar) = &*st.overlay_poll_live;
|
||||
*lock.lock().unwrap_or_else(|e| e.into_inner()) = true;
|
||||
*lock.lock().unwrap_or_else(std::sync::PoisonError::into_inner) = true;
|
||||
cvar.notify_one();
|
||||
}
|
||||
|
||||
@@ -1242,18 +1241,18 @@ fn show_overlay(app: AppHandle) -> Result<(), String> {
|
||||
use windows::Win32::UI::WindowsAndMessaging::{SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOSIZE, SWP_NOZORDER};
|
||||
if let Ok(raw) = win.hwnd() {
|
||||
if let Some((vl, vt, vr, vb)) = visible_window_bounds(raw.0 as isize) {
|
||||
let center = POINT { x: (vl + vr) / 2, y: (vt + vb) / 2 };
|
||||
let center = POINT { x: i32::midpoint(vl, vr), y: i32::midpoint(vt, vb) };
|
||||
let hmon = unsafe { MonitorFromPoint(center, MONITOR_DEFAULTTONULL) };
|
||||
if hmon.0.is_null() {
|
||||
let hwnd = HWND(raw.0 as *mut std::ffi::c_void);
|
||||
let hwnd = HWND(raw.0.cast::<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() {
|
||||
let mut mi = MONITORINFO { cbSize: size_of::<MONITORINFO>() as u32, ..Default::default() };
|
||||
if unsafe { GetMonitorInfoW(primary, &raw mut mi) }.as_bool() {
|
||||
let work = mi.rcWork;
|
||||
let w = vr - vl;
|
||||
let h = vb - vt;
|
||||
let cx = (work.left + work.right) / 2 - w / 2;
|
||||
let cy = (work.top + work.bottom) / 2 - h / 2;
|
||||
let cx = i32::midpoint(work.left, work.right) - w / 2;
|
||||
let cy = i32::midpoint(work.top, work.bottom) - h / 2;
|
||||
drop(
|
||||
unsafe { SetWindowPos(hwnd, Some(HWND_TOP), cx, cy, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE) },
|
||||
);
|
||||
@@ -1275,7 +1274,7 @@ fn hide_overlay(app: AppHandle) -> Result<(), String> {
|
||||
{
|
||||
let st = app.state::<AppState>();
|
||||
let (lock, cvar) = &*st.overlay_poll_live;
|
||||
*lock.lock().unwrap_or_else(|e| e.into_inner()) = false;
|
||||
*lock.lock().unwrap_or_else(std::sync::PoisonError::into_inner) = false;
|
||||
cvar.notify_one();
|
||||
}
|
||||
win.hide().map_err(|e| format!("hiding overlay: {e:#}"))
|
||||
@@ -1349,7 +1348,7 @@ 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 std::ffi::c_void);
|
||||
let hwnd = HWND(raw.0.cast::<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;
|
||||
@@ -1407,16 +1406,16 @@ fn open_window_picker(
|
||||
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 std::ffi::c_void);
|
||||
let hwnd = HWND(h.0.cast::<std::ffi::c_void>());
|
||||
let mut gr = RECT::default();
|
||||
drop(unsafe { GetWindowRect(hwnd, &mut gr) });
|
||||
drop(unsafe { GetWindowRect(hwnd, &raw mut gr) });
|
||||
let mut dr = RECT::default();
|
||||
drop(unsafe {
|
||||
DwmGetWindowAttribute(
|
||||
hwnd,
|
||||
DWMWA_EXTENDED_FRAME_BOUNDS,
|
||||
&raw mut dr as *mut RECT as *mut std::ffi::c_void,
|
||||
std::mem::size_of::<RECT>() as u32,
|
||||
(&raw mut dr).cast::<RECT>().cast::<std::ffi::c_void>(),
|
||||
size_of::<RECT>() as u32,
|
||||
)
|
||||
});
|
||||
tracing::debug!(
|
||||
@@ -1460,8 +1459,8 @@ fn visible_window_bounds(hwnd_raw: isize) -> Option<(i32, i32, i32, i32)> {
|
||||
DwmGetWindowAttribute(
|
||||
hwnd,
|
||||
DWMWA_EXTENDED_FRAME_BOUNDS,
|
||||
&mut dwm as *mut RECT as *mut std::ffi::c_void,
|
||||
std::mem::size_of::<RECT>() as u32,
|
||||
(&raw mut dwm).cast::<std::ffi::c_void>(),
|
||||
size_of::<RECT>() as u32,
|
||||
)
|
||||
}
|
||||
.is_ok()
|
||||
@@ -1471,7 +1470,7 @@ fn visible_window_bounds(hwnd_raw: isize) -> Option<(i32, i32, i32, i32)> {
|
||||
return Some((dwm.left, dwm.top, dwm.right, dwm.bottom));
|
||||
}
|
||||
let mut outer = RECT::default();
|
||||
if unsafe { GetWindowRect(hwnd, &mut outer) }.is_ok() {
|
||||
if unsafe { GetWindowRect(hwnd, &raw mut outer) }.is_ok() {
|
||||
Some((outer.left, outer.top, outer.right, outer.bottom))
|
||||
} else {
|
||||
None
|
||||
@@ -1485,7 +1484,7 @@ fn dwm_insets(hwnd_raw: isize) -> (i32, i32, i32, i32) {
|
||||
|
||||
let hwnd = HWND(hwnd_raw as *mut std::ffi::c_void);
|
||||
let mut outer = RECT::default();
|
||||
if unsafe { GetWindowRect(hwnd, &mut outer) }.is_err() {
|
||||
if unsafe { GetWindowRect(hwnd, &raw mut outer) }.is_err() {
|
||||
return (0, 0, 0, 0);
|
||||
}
|
||||
let mut dwm = RECT::default();
|
||||
@@ -1493,8 +1492,8 @@ fn dwm_insets(hwnd_raw: isize) -> (i32, i32, i32, i32) {
|
||||
DwmGetWindowAttribute(
|
||||
hwnd,
|
||||
DWMWA_EXTENDED_FRAME_BOUNDS,
|
||||
&mut dwm as *mut RECT as *mut std::ffi::c_void,
|
||||
std::mem::size_of::<RECT>() as u32,
|
||||
(&raw mut dwm).cast::<std::ffi::c_void>(),
|
||||
size_of::<RECT>() as u32,
|
||||
)
|
||||
};
|
||||
if r.is_err() || dwm.right <= dwm.left || dwm.bottom <= dwm.top {
|
||||
@@ -1525,8 +1524,8 @@ fn scale_factor_at_point(x: i32, y: i32) -> f64 {
|
||||
GetDpiForMonitor(
|
||||
hmonitor,
|
||||
MONITOR_DPI_TYPE(0), // MdtEffectiveDpi
|
||||
&mut dpi_x,
|
||||
&mut dpi_y,
|
||||
&raw mut dpi_x,
|
||||
&raw mut dpi_y,
|
||||
)
|
||||
};
|
||||
if hr.is_ok() && dpi_x > 0 {
|
||||
@@ -1567,8 +1566,7 @@ fn set_overlay_to_window(
|
||||
// visible content sits inside the DWM inset).
|
||||
let (li, ti, ri, bi) = win
|
||||
.hwnd()
|
||||
.map(|h| dwm_insets(h.0 as isize))
|
||||
.unwrap_or((0, 0, 0, 0));
|
||||
.map_or((0, 0, 0, 0), |h| dwm_insets(h.0 as isize));
|
||||
|
||||
let outer_x = visible_left - li;
|
||||
let outer_y = visible_top - ti;
|
||||
@@ -1582,7 +1580,7 @@ fn set_overlay_to_window(
|
||||
use windows::Win32::UI::WindowsAndMessaging::{
|
||||
SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOZORDER,
|
||||
};
|
||||
let hwnd = HWND(raw.0 as *mut std::ffi::c_void);
|
||||
let hwnd = HWND(raw.0.cast::<std::ffi::c_void>());
|
||||
unsafe {
|
||||
SetWindowPos(
|
||||
hwnd,
|
||||
@@ -1639,9 +1637,7 @@ fn reveal_in_explorer(path: String) -> Result<(), String> {
|
||||
|
||||
let canonical = std::fs::canonicalize(&path).ok();
|
||||
let normalized = canonical
|
||||
.as_ref()
|
||||
.map(|p| p.to_string_lossy().into_owned())
|
||||
.unwrap_or_else(|| path.clone());
|
||||
.as_ref().map_or_else(|| path.clone(), |p| p.to_string_lossy().into_owned());
|
||||
let stripped = normalized
|
||||
.strip_prefix(r"\\?\")
|
||||
.unwrap_or(&normalized)
|
||||
@@ -1729,7 +1725,7 @@ fn diagnostics_info(state: State<'_, AppState>) -> DiagnosticsInfo {
|
||||
String::from_utf8_lossy(&o.stdout)
|
||||
.lines()
|
||||
.next()
|
||||
.map(|s| s.to_string())
|
||||
.map(ToString::to_string)
|
||||
})
|
||||
.unwrap_or_else(|| "ffmpeg present (version unreadable)".to_string())
|
||||
} else {
|
||||
@@ -1884,7 +1880,7 @@ async fn export(app: AppHandle, state: State<'_, AppState>, request: ExportReque
|
||||
|
||||
// Run the (potentially minutes-long) ffmpeg encode on a blocking thread so
|
||||
// we don't hold a Tauri async worker for the whole duration.
|
||||
let ffmpeg_arc = std::sync::Arc::new(ffmpeg);
|
||||
let ffmpeg_arc = Arc::new(ffmpeg);
|
||||
let ffmpeg_for_task = ffmpeg_arc.clone();
|
||||
let result = tauri::async_runtime::spawn_blocking(move || {
|
||||
encode::transcode(&ffmpeg_for_task, &req_with_progress)
|
||||
@@ -1894,8 +1890,7 @@ async fn export(app: AppHandle, state: State<'_, AppState>, request: ExportReque
|
||||
result.map_err(|e| format!("{e:#}"))?;
|
||||
|
||||
let size_bytes = std::fs::metadata(&out_path)
|
||||
.map(|m| m.len())
|
||||
.unwrap_or(0);
|
||||
.map_or(0, |m| m.len());
|
||||
Ok(ExportResult {
|
||||
met_target: size_bytes <= request.target_bytes,
|
||||
target_bytes: request.target_bytes,
|
||||
@@ -1961,7 +1956,7 @@ pub fn run() {
|
||||
overlay_poll_shutdown: Arc::new(AtomicBool::new(false)),
|
||||
export_cancel: Arc::new(AtomicBool::new(false)),
|
||||
overlay_aspect_ratio: Mutex::new(None),
|
||||
overlay_poll_live: Arc::new((std::sync::Mutex::new(false), std::sync::Condvar::new())),
|
||||
overlay_poll_live: Arc::new((Mutex::new(false), std::sync::Condvar::new())),
|
||||
};
|
||||
|
||||
let app = tauri::Builder::default()
|
||||
@@ -2034,7 +2029,7 @@ pub fn run() {
|
||||
let app_dir = app.state::<AppState>().app_dir.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
// Skip the network call if we checked within the last 6 hours.
|
||||
if !updates::should_check(&app_dir, std::time::Duration::from_secs(6 * 3600)) {
|
||||
if !updates::should_check(&app_dir, std::time::Duration::from_hours(6)) {
|
||||
tracing::debug!("update check skipped (TTL not elapsed)");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user