gif encode retry loop (up to 5 passes, adjusts resolution/fps until within 15% of target size), aspect ratio enforcement via rust command instead of unreliable cross-window emit
This commit is contained in:
+35
-6
@@ -43,6 +43,7 @@ pub struct AppState {
|
||||
pub session: Mutex<Option<SessionState>>,
|
||||
pub picker: Mutex<Option<window_picker::PickerSession>>,
|
||||
pub overlay_poll_shutdown: Arc<AtomicBool>,
|
||||
pub overlay_aspect_ratio: Mutex<Option<f64>>,
|
||||
}
|
||||
|
||||
pub struct SessionState {
|
||||
@@ -904,21 +905,47 @@ fn hide_overlay(app: AppHandle) -> Result<(), String> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn set_overlay_size(app: AppHandle, width: u32, height: u32) -> Result<(), String> {
|
||||
fn set_overlay_size(app: AppHandle, state: State<'_, AppState>, width: u32, height: u32) -> Result<(), String> {
|
||||
use tauri::{LogicalSize, Size};
|
||||
let win = app
|
||||
.get_webview_window("overlay")
|
||||
.ok_or_else(|| "overlay window not found".to_string())?;
|
||||
// Add the titlebar + border to the logical content size so the captured
|
||||
// region matches the requested preset.
|
||||
let final_w = width as f64 + (OVERLAY_BORDER_LOGICAL_PX * 2.0);
|
||||
let final_h =
|
||||
height as f64 + OVERLAY_TITLEBAR_LOGICAL_PX + (OVERLAY_BORDER_LOGICAL_PX * 2.0);
|
||||
let ratio = lock(&state.overlay_aspect_ratio);
|
||||
let (w, mut h) = (width as f64, height as f64);
|
||||
if let Some(r) = *ratio {
|
||||
h = w / r;
|
||||
}
|
||||
let final_w = w + (OVERLAY_BORDER_LOGICAL_PX * 2.0);
|
||||
let final_h = h + OVERLAY_TITLEBAR_LOGICAL_PX + (OVERLAY_BORDER_LOGICAL_PX * 2.0);
|
||||
win.set_size(Size::Logical(LogicalSize::new(final_w, final_h)))
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn set_overlay_aspect(app: AppHandle, state: State<'_, AppState>, ratio: Option<f64>) -> Result<(), String> {
|
||||
*lock(&state.overlay_aspect_ratio) = ratio;
|
||||
if let Some(r) = ratio {
|
||||
// Enforce on current size
|
||||
let win = app
|
||||
.get_webview_window("overlay")
|
||||
.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| e.to_string())?;
|
||||
let cur_w = sz.width as f64 / scale;
|
||||
let cur_h = sz.height as f64 / scale;
|
||||
let target_h = cur_w / r;
|
||||
if (target_h - cur_h).abs() > 1.0 {
|
||||
use tauri::{LogicalSize, Size};
|
||||
let final_w = cur_w + (OVERLAY_BORDER_LOGICAL_PX * 2.0);
|
||||
let final_h = target_h + OVERLAY_TITLEBAR_LOGICAL_PX + (OVERLAY_BORDER_LOGICAL_PX * 2.0);
|
||||
win.set_size(Size::Logical(LogicalSize::new(final_w, final_h)))
|
||||
.map_err(|e| e.to_string())?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn list_windows() -> Vec<windows_list::WindowInfo> {
|
||||
windows_list::list_visible_windows()
|
||||
@@ -1373,6 +1400,7 @@ pub fn run() {
|
||||
session: Mutex::new(None),
|
||||
picker: Mutex::new(None),
|
||||
overlay_poll_shutdown: Arc::new(AtomicBool::new(false)),
|
||||
overlay_aspect_ratio: Mutex::new(None),
|
||||
};
|
||||
|
||||
tauri::Builder::default()
|
||||
@@ -1472,6 +1500,7 @@ pub fn run() {
|
||||
show_overlay,
|
||||
hide_overlay,
|
||||
set_overlay_size,
|
||||
set_overlay_aspect,
|
||||
set_overlay_to_window,
|
||||
list_windows,
|
||||
open_window_picker,
|
||||
|
||||
Reference in New Issue
Block a user