hoist item declarations above statements
This commit is contained in:
@@ -1211,8 +1211,8 @@ fn run_impl(
|
|||||||
// Stderr reader: collect bytes for diagnostics. No more frame regex.
|
// Stderr reader: collect bytes for diagnostics. No more frame regex.
|
||||||
let mut stderr_handle: Option<thread::JoinHandle<Vec<u8>>> = stderr.map(move |serr| {
|
let mut stderr_handle: Option<thread::JoinHandle<Vec<u8>>> = stderr.map(move |serr| {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut collected = Vec::new();
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
let mut collected = Vec::new();
|
||||||
let mut s = serr;
|
let mut s = serr;
|
||||||
drop(s.read_to_end(&mut collected));
|
drop(s.read_to_end(&mut collected));
|
||||||
collected
|
collected
|
||||||
|
|||||||
+29
-23
@@ -989,6 +989,15 @@ fn estimate_gif_params(request: PreviewRequest) -> GifEstimate {
|
|||||||
GifEstimate { width: w, fps, height, dims_label }
|
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
|
/// 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
|
/// interpolate on slider drag without an IPC per debounce tick. The grid is
|
||||||
/// geometric from 100KB to 200MB.
|
/// geometric from 100KB to 200MB.
|
||||||
@@ -999,16 +1008,8 @@ fn estimate_gif_params_table(request: PreviewRequest) -> GifEstimateTable {
|
|||||||
let fps = request.fps;
|
let fps = request.fps;
|
||||||
let mode = request.gif_budget_mode;
|
let mode = request.gif_budget_mode;
|
||||||
|
|
||||||
// Geometric grid: 100KB, 200KB, 500KB, 1MB, 2MB, 5MB, 10MB, 20MB, 50MB, 100MB, 200MB
|
let mut points = Vec::with_capacity(GIF_ESTIMATE_GRID.len());
|
||||||
const GRID: &[u64] = &[
|
for &target in GIF_ESTIMATE_GRID {
|
||||||
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 budget = encode::GifBudgetInput {
|
let budget = encode::GifBudgetInput {
|
||||||
gif_colors: colors,
|
gif_colors: colors,
|
||||||
target_bytes: target,
|
target_bytes: target,
|
||||||
@@ -1269,6 +1270,12 @@ fn mark_overlay_excluded_from_capture(win: &tauri::WebviewWindow) -> Result<(),
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn show_overlay(app: AppHandle) -> Result<(), String> {
|
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
|
let win = app
|
||||||
.get_webview_window("overlay")
|
.get_webview_window("overlay")
|
||||||
.ok_or_else(|| "overlay window not found".to_string())?;
|
.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
|
// 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 Ok(raw) = win.hwnd() {
|
||||||
if let Some((vl, vt, vr, vb)) = visible_window_bounds(raw.0 as isize) {
|
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) };
|
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<f64> {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn enforce_overlay_aspect(app: AppHandle, state: State<'_, AppState>) -> Result<(), String> {
|
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) {
|
let ratio = match *lock(&state.overlay_aspect_ratio) {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
@@ -1407,8 +1412,6 @@ fn enforce_overlay_aspect(app: AppHandle, state: State<'_, AppState>) -> Result<
|
|||||||
return Ok(()); // already correct
|
return Ok(()); // already correct
|
||||||
}
|
}
|
||||||
// Use Win32 SetWindowPos for reliable enforcement
|
// 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 raw = win.hwnd().map_err(|e| format!("hwnd: {e}"))?;
|
||||||
let hwnd = HWND(raw.0.cast::<std::ffi::c_void>());
|
let hwnd = HWND(raw.0.cast::<std::ffi::c_void>());
|
||||||
// Compute outer size including borders
|
// Compute outer size including borders
|
||||||
@@ -1435,6 +1438,8 @@ fn open_window_picker(
|
|||||||
app: AppHandle,
|
app: AppHandle,
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
use tauri::{PhysicalPosition, PhysicalSize, Position, Size};
|
||||||
|
|
||||||
let (mw, mh) =
|
let (mw, mh) =
|
||||||
capture::primary_monitor_dims().map_err(|e| format!("{e:#}"))?;
|
capture::primary_monitor_dims().map_err(|e| format!("{e:#}"))?;
|
||||||
|
|
||||||
@@ -1456,7 +1461,6 @@ fn open_window_picker(
|
|||||||
let picker = app
|
let picker = app
|
||||||
.get_webview_window("picker")
|
.get_webview_window("picker")
|
||||||
.ok_or_else(|| "picker window not found".to_string())?;
|
.ok_or_else(|| "picker window not found".to_string())?;
|
||||||
use tauri::{PhysicalPosition, PhysicalSize, Position, Size};
|
|
||||||
picker
|
picker
|
||||||
.set_size(Size::Physical(PhysicalSize::new(mw, mh)))
|
.set_size(Size::Physical(PhysicalSize::new(mw, mh)))
|
||||||
.map_err(|e| format!("setting picker size: {e:#}"))?;
|
.map_err(|e| format!("setting picker size: {e:#}"))?;
|
||||||
@@ -1618,6 +1622,11 @@ fn set_overlay_to_window(
|
|||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
use windows::Win32::Foundation::HWND;
|
||||||
|
use windows::Win32::UI::WindowsAndMessaging::{
|
||||||
|
SetWindowPos, HWND_TOP, SWP_NOACTIVATE, SWP_NOZORDER,
|
||||||
|
};
|
||||||
|
|
||||||
let win = app
|
let win = app
|
||||||
.get_webview_window("overlay")
|
.get_webview_window("overlay")
|
||||||
.ok_or_else(|| "overlay window not found".to_string())?;
|
.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
|
// Bypass Tauri's set_position/set_size which adds extra pixels for
|
||||||
// some unknown reason. Use Win32 SetWindowPos with explicit outer rect.
|
// some unknown reason. Use Win32 SetWindowPos with explicit outer rect.
|
||||||
let raw = win.hwnd().map_err(|e| format!("hwnd: {e}"))?;
|
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::<std::ffi::c_void>());
|
let hwnd = HWND(raw.0.cast::<std::ffi::c_void>());
|
||||||
// SAFETY: `hwnd` is the overlay's live handle and every dimension is a
|
// SAFETY: `hwnd` is the overlay's live handle and every dimension is a
|
||||||
// plain integer computed above; no pointers are passed.
|
// plain integer computed above; no pointers are passed.
|
||||||
@@ -1738,10 +1743,11 @@ fn reveal_in_explorer(path: String) -> Result<(), String> {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn open_url(url: String) -> Result<(), String> {
|
fn open_url(url: String) -> Result<(), String> {
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
|
||||||
if !url.starts_with("http://") && !url.starts_with("https://") {
|
if !url.starts_with("http://") && !url.starts_with("https://") {
|
||||||
return Err("only http/https URLs are supported".to_string());
|
return Err("only http/https URLs are supported".to_string());
|
||||||
}
|
}
|
||||||
use std::os::windows::process::CommandExt;
|
|
||||||
std::process::Command::new("cmd")
|
std::process::Command::new("cmd")
|
||||||
.raw_arg(format!("/C start \"\" \"{url}\""))
|
.raw_arg(format!("/C start \"\" \"{url}\""))
|
||||||
.spawn()
|
.spawn()
|
||||||
|
|||||||
@@ -67,18 +67,20 @@ pub(crate) async fn download_to<F>(url: &str, dest: &Path, mut on_progress: F) -
|
|||||||
where
|
where
|
||||||
F: FnMut(u64, Option<u64>) + Send,
|
F: FnMut(u64, Option<u64>) + Send,
|
||||||
{
|
{
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
if let Some(parent) = dest.parent() {
|
if let Some(parent) = dest.parent() {
|
||||||
std::fs::create_dir_all(parent).context("creating update parent dir")?;
|
std::fs::create_dir_all(parent).context("creating update parent dir")?;
|
||||||
}
|
}
|
||||||
let client = reqwest::Client::builder()
|
let client = reqwest::Client::builder()
|
||||||
.user_agent(concat!("ByteSize/", env!("CARGO_PKG_VERSION")))
|
.user_agent(concat!("ByteSize/", env!("CARGO_PKG_VERSION")))
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let resp = client.get(url).send().await?.error_for_status()?;
|
let resp = client.get(url).send().await?.error_for_status()?;
|
||||||
let total = resp.content_length();
|
let total = resp.content_length();
|
||||||
let mut downloaded = 0u64;
|
let mut downloaded = 0u64;
|
||||||
let mut stream = resp.bytes_stream();
|
let mut stream = resp.bytes_stream();
|
||||||
let mut file = std::fs::File::create(dest).context("creating update file")?;
|
let mut file = std::fs::File::create(dest).context("creating update file")?;
|
||||||
use std::io::Write;
|
|
||||||
while let Some(chunk) = stream.next().await {
|
while let Some(chunk) = stream.next().await {
|
||||||
let chunk = chunk?;
|
let chunk = chunk?;
|
||||||
file.write_all(&chunk)?;
|
file.write_all(&chunk)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user