1use tauri::{AppHandle, Emitter, Manager, WebviewWindow};
6
7use crate::{command::CommandResult, window};
8
9pub fn get_window(app: &AppHandle, label: &str) -> CommandResult<WebviewWindow> {
12 app.get_webview_window(label)
13 .ok_or_else(|| format!("{label} window not found"))
14}
15
16pub fn toggle_window_visibility(app: &AppHandle, label: &str) -> CommandResult<()> {
18 let Some(handle) = app.get_webview_window(label) else {
19 return Ok(());
20 };
21 if window::is_visible(&handle) {
22 window::hide(&handle)
23 } else {
24 window::show_and_focus(&handle)
25 }
26}
27
28pub fn emit_or_warn<S: serde::Serialize + Clone>(window: &WebviewWindow, event: &str, payload: S) {
32 if let Err(err) = window.emit(event, payload) {
33 tracing::warn!("failed to emit {event}: {err}");
34 }
35}