diff --git a/apps/desktop/src-tauri/src/chat.rs b/apps/desktop/src-tauri/src/chat.rs index b1a8b80..af099c1 100644 --- a/apps/desktop/src-tauri/src/chat.rs +++ b/apps/desktop/src-tauri/src/chat.rs @@ -910,3 +910,37 @@ pub fn minimize_chat_window(app: &tauri::AppHandle, ticket_id: &str) -> Result<( } Ok(()) } + +/// Redimensiona a janela de chat para modo minimizado (chip) ou expandido +pub fn set_chat_minimized(app: &tauri::AppHandle, ticket_id: &str, minimized: bool) -> Result<(), String> { + let label = format!("chat-{}", ticket_id); + let window = app.get_webview_window(&label).ok_or("Janela nao encontrada")?; + + // Tamanhos + let (width, height) = if minimized { + (200.0, 56.0) // Tamanho do chip + } else { + (380.0, 520.0) // Tamanho expandido + }; + + // Calcular posicao no canto inferior direito + let (x, y) = if let Some(monitor) = window.current_monitor().ok().flatten() { + let size = monitor.size(); + let scale = monitor.scale_factor(); + let margin = 20.0; + let taskbar_height = 50.0; + ( + (size.width as f64 / scale) - width - margin, + (size.height as f64 / scale) - height - margin - taskbar_height, + ) + } else { + (100.0, 100.0) + }; + + // Aplicar novo tamanho e posicao + window.set_size(tauri::LogicalSize::new(width, height)).map_err(|e| e.to_string())?; + window.set_position(tauri::LogicalPosition::new(x, y)).map_err(|e| e.to_string())?; + + crate::log_info!("Chat {} -> minimized={}", ticket_id, minimized); + Ok(()) +} diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 4833a6a..396e9de 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -244,6 +244,11 @@ fn stop_chat_polling(state: tauri::State) -> Result<(), String> { Ok(()) } +#[tauri::command] +fn is_chat_using_sse(state: tauri::State) -> bool { + state.is_using_sse() +} + #[tauri::command] fn get_chat_sessions(state: tauri::State) -> Vec { state.get_sessions() @@ -338,6 +343,11 @@ fn minimize_chat_window(app: tauri::AppHandle, ticket_id: String) -> Result<(), chat::minimize_chat_window(&app, &ticket_id) } +#[tauri::command] +fn set_chat_minimized(app: tauri::AppHandle, ticket_id: String, minimized: bool) -> Result<(), String> { + chat::set_chat_minimized(&app, &ticket_id, minimized) +} + #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() @@ -395,6 +405,7 @@ pub fn run() { // Chat commands start_chat_polling, stop_chat_polling, + is_chat_using_sse, get_chat_sessions, fetch_chat_sessions, fetch_chat_messages, @@ -402,7 +413,8 @@ pub fn run() { upload_chat_file, open_chat_window, close_chat_window, - minimize_chat_window + minimize_chat_window, + set_chat_minimized ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/apps/desktop/src/chat/ChatWidget.tsx b/apps/desktop/src/chat/ChatWidget.tsx index e643ca9..220e602 100644 --- a/apps/desktop/src/chat/ChatWidget.tsx +++ b/apps/desktop/src/chat/ChatWidget.tsx @@ -68,9 +68,13 @@ export function ChatWidget({ ticketId }: ChatWidgetProps) { useEffect(() => { if (hadSessionRef.current && !hasSession) { setIsMinimized(true) + // Redimensionar janela para modo minimizado + invoke("set_chat_minimized", { ticketId, minimized: true }).catch(err => { + console.error("Erro ao minimizar janela automaticamente:", err) + }) } hadSessionRef.current = hasSession - }, [hasSession]) + }, [hasSession, ticketId]) // Carregar configuracao do store const loadConfig = useCallback(async () => { @@ -306,8 +310,22 @@ export function ChatWidget({ ticketId }: ChatWidgetProps) { } } - const handleMinimize = () => { + const handleMinimize = async () => { setIsMinimized(true) + try { + await invoke("set_chat_minimized", { ticketId, minimized: true }) + } catch (err) { + console.error("Erro ao minimizar janela:", err) + } + } + + const handleExpand = async () => { + setIsMinimized(false) + try { + await invoke("set_chat_minimized", { ticketId, minimized: false }) + } catch (err) { + console.error("Erro ao expandir janela:", err) + } } const handleClose = () => { @@ -357,9 +375,9 @@ export function ChatWidget({ ticketId }: ChatWidgetProps) { // Versão minimizada (chip compacto igual web) if (isMinimized) { return ( -
+