diff --git a/src-tauri/src/encode.rs b/src-tauri/src/encode.rs index 89b2ac2..da5bb2d 100644 --- a/src-tauri/src/encode.rs +++ b/src-tauri/src/encode.rs @@ -1211,8 +1211,8 @@ fn run_impl( // Stderr reader: collect bytes for diagnostics. No more frame regex. let mut stderr_handle: Option>> = stderr.map(move |serr| { thread::spawn(move || { - let mut collected = Vec::new(); use std::io::Read; + let mut collected = Vec::new(); let mut s = serr; drop(s.read_to_end(&mut collected)); collected diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1d90c90..37db735 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -989,6 +989,15 @@ fn estimate_gif_params(request: PreviewRequest) -> GifEstimate { GifEstimate { width: w, fps, height, dims_label } } +/// Geometric grid from 100KB to 200MB, used to sample the GIF size estimator +/// across a range of targets so the frontend can interpolate locally. +const GIF_ESTIMATE_GRID: &[u64] = &[ + 100_000, 200_000, 500_000, + 1_048_576, 2_097_152, 5_242_880, + 10_485_760, 20_971_520, 52_428_800, + 104_857_600, 209_715_200, +]; + /// 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. @@ -999,16 +1008,8 @@ fn estimate_gif_params_table(request: PreviewRequest) -> GifEstimateTable { let fps = request.fps; let mode = request.gif_budget_mode; - // Geometric grid: 100KB, 200KB, 500KB, 1MB, 2MB, 5MB, 10MB, 20MB, 50MB, 100MB, 200MB - const GRID: &[u64] = &[ - 100_000, 200_000, 500_000, - 1_048_576, 2_097_152, 5_242_880, - 10_485_760, 20_971_520, 52_428_800, - 104_857_600, 209_715_200, - ]; - - let mut points = Vec::with_capacity(GRID.len()); - for &target in GRID { + let mut points = Vec::with_capacity(GIF_ESTIMATE_GRID.len()); + for &target in GIF_ESTIMATE_GRID { let budget = encode::GifBudgetInput { gif_colors: colors, target_bytes: target, @@ -1269,6 +1270,12 @@ fn mark_overlay_excluded_from_capture(win: &tauri::WebviewWindow) -> Result<(), #[tauri::command] fn show_overlay(app: AppHandle) -> Result<(), String> { + use windows::Win32::Foundation::{HWND, POINT}; + use windows::Win32::Graphics::Gdi::{ + GetMonitorInfoW, MonitorFromPoint, MONITOR_DEFAULTTOPRIMARY, MONITOR_DEFAULTTONULL, MONITORINFO, + }; + use windows::Win32::UI::WindowsAndMessaging::{SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOSIZE, SWP_NOZORDER}; + let win = app .get_webview_window("overlay") .ok_or_else(|| "overlay window not found".to_string())?; @@ -1284,11 +1291,6 @@ fn show_overlay(app: AppHandle) -> Result<(), String> { } // If the overlay is off-screen (monitor disconnected), center on primary - use windows::Win32::Foundation::{HWND, POINT}; - use windows::Win32::Graphics::Gdi::{ - GetMonitorInfoW, MonitorFromPoint, MONITOR_DEFAULTTOPRIMARY, MONITOR_DEFAULTTONULL, MONITORINFO, - }; - 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: i32::midpoint(vl, vr), y: i32::midpoint(vt, vb) }; @@ -1391,6 +1393,9 @@ fn get_overlay_aspect(state: State<'_, AppState>) -> Option { #[tauri::command] fn enforce_overlay_aspect(app: AppHandle, state: State<'_, AppState>) -> Result<(), String> { + 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(()), @@ -1407,8 +1412,6 @@ fn enforce_overlay_aspect(app: AppHandle, state: State<'_, AppState>) -> Result< return Ok(()); // already correct } // Use Win32 SetWindowPos for reliable enforcement - 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.cast::()); // Compute outer size including borders @@ -1435,6 +1438,8 @@ fn open_window_picker( app: AppHandle, state: State<'_, AppState>, ) -> Result<(), String> { + use tauri::{PhysicalPosition, PhysicalSize, Position, Size}; + let (mw, mh) = capture::primary_monitor_dims().map_err(|e| format!("{e:#}"))?; @@ -1456,7 +1461,6 @@ fn open_window_picker( let picker = app .get_webview_window("picker") .ok_or_else(|| "picker window not found".to_string())?; - use tauri::{PhysicalPosition, PhysicalSize, Position, Size}; picker .set_size(Size::Physical(PhysicalSize::new(mw, mh))) .map_err(|e| format!("setting picker size: {e:#}"))?; @@ -1618,6 +1622,11 @@ fn set_overlay_to_window( width: u32, height: u32, ) -> Result<(), String> { + use windows::Win32::Foundation::HWND; + use windows::Win32::UI::WindowsAndMessaging::{ + SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOZORDER, + }; + let win = app .get_webview_window("overlay") .ok_or_else(|| "overlay window not found".to_string())?; @@ -1651,10 +1660,6 @@ fn set_overlay_to_window( // Bypass Tauri's set_position/set_size which adds extra pixels for // some unknown reason. Use Win32 SetWindowPos with explicit outer rect. let raw = win.hwnd().map_err(|e| format!("hwnd: {e}"))?; - use windows::Win32::Foundation::HWND; - use windows::Win32::UI::WindowsAndMessaging::{ - SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOZORDER, - }; let hwnd = HWND(raw.0.cast::()); // SAFETY: `hwnd` is the overlay's live handle and every dimension is a // plain integer computed above; no pointers are passed. @@ -1738,10 +1743,11 @@ fn reveal_in_explorer(path: String) -> Result<(), String> { #[tauri::command] fn open_url(url: String) -> Result<(), String> { + use std::os::windows::process::CommandExt; + if !url.starts_with("http://") && !url.starts_with("https://") { return Err("only http/https URLs are supported".to_string()); } - use std::os::windows::process::CommandExt; std::process::Command::new("cmd") .raw_arg(format!("/C start \"\" \"{url}\"")) .spawn() diff --git a/src-tauri/src/updates.rs b/src-tauri/src/updates.rs index 3424207..67a5a60 100644 --- a/src-tauri/src/updates.rs +++ b/src-tauri/src/updates.rs @@ -67,18 +67,20 @@ pub(crate) async fn download_to(url: &str, dest: &Path, mut on_progress: F) - where F: FnMut(u64, Option) + Send, { + use std::io::Write; + if let Some(parent) = dest.parent() { std::fs::create_dir_all(parent).context("creating update parent dir")?; } let client = reqwest::Client::builder() .user_agent(concat!("ByteSize/", env!("CARGO_PKG_VERSION"))) .build()?; + let resp = client.get(url).send().await?.error_for_status()?; let total = resp.content_length(); let mut downloaded = 0u64; let mut stream = resp.bytes_stream(); let mut file = std::fs::File::create(dest).context("creating update file")?; - use std::io::Write; while let Some(chunk) = stream.next().await { let chunk = chunk?; file.write_all(&chunk)?;