Make an official event

This commit is contained in:
Robert Clabough 2026-08-14 10:52:24 -07:00
parent 8793680a51
commit 42b662c170
2 changed files with 7 additions and 9 deletions

View file

@ -42,6 +42,10 @@ listen("update_state", (event) => {
state.value = event.payload as AppState;
});
listen("window_visibility_change", () => {
document.dispatchEvent(new Event("visibilitychange"));
});
setupHooks();
initialNavigation(state);

View file

@ -49,7 +49,7 @@ use log4rs::{
encode::pattern::PatternEncoder,
};
use tauri::{
AppHandle, LogicalPosition, LogicalSize, Manager, RunEvent, WebviewBuilder, WebviewUrl,
AppHandle, Emitter, LogicalPosition, LogicalSize, Manager, RunEvent, WebviewBuilder, WebviewUrl,
WindowBuilder, WindowEvent,
menu::{Menu, MenuItem, PredefinedMenuItem},
tray::TrayIconBuilder,
@ -391,11 +391,7 @@ pub fn run() {
#[cfg(target_os = "linux")]
{
// Resume webview rendering after showing
if let Some(win) = app.get_window("main") {
for wv in win.webviews() {
let _ = wv.eval("document.dispatchEvent(new Event('visibilitychange'))");
}
}
app_emit!(app, "window_visibility_change", ());
}
app.get_window("main")
@ -461,9 +457,7 @@ pub fn run() {
// Pause webview rendering before hiding to prevent idle CPU usage
#[cfg(target_os = "linux")]
{
for wv in window.webviews() {
let _ = wv.eval("document.dispatchEvent(new Event('visibilitychange'))");
}
let _ = window.app_handle().emit("window_visibility_change", ());
}
window.hide().expect("Failed to hide window in tray");