fix: redimensiona janela de chat ao minimizar/expandir
- Adiciona funcao set_chat_minimized que redimensiona a janela - Modo minimizado: 200x56 (tamanho do chip) - Modo expandido: 380x520 (tamanho completo) - Janela reposiciona automaticamente no canto inferior direito - Adiciona comando is_chat_using_sse para verificar modo de conexao 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
53376fe5b0
commit
a0edaf8adb
3 changed files with 69 additions and 5 deletions
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -244,6 +244,11 @@ fn stop_chat_polling(state: tauri::State<ChatRuntime>) -> Result<(), String> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn is_chat_using_sse(state: tauri::State<ChatRuntime>) -> bool {
|
||||
state.is_using_sse()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_chat_sessions(state: tauri::State<ChatRuntime>) -> Vec<ChatSession> {
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div className="flex h-screen flex-col items-center justify-end bg-transparent p-4">
|
||||
<div className="flex h-full w-full items-center justify-center bg-transparent">
|
||||
<button
|
||||
onClick={() => setIsMinimized(false)}
|
||||
onClick={handleExpand}
|
||||
className="flex items-center gap-2 rounded-full bg-black px-4 py-2 text-white shadow-lg hover:bg-black/90"
|
||||
>
|
||||
<MessageCircle className="size-4" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue