hoist item declarations above statements
This commit is contained in:
+29
-23
@@ -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<f64> {
|
||||
|
||||
#[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::<std::ffi::c_void>());
|
||||
// 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::<std::ffi::c_void>());
|
||||
// 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()
|
||||
|
||||
Reference in New Issue
Block a user