Fixing linux bug where client would never actually quit (#469)

* Fixing linux bug where client would never actually quit

* Fixing window minimizing to tray

* Make an official event

---------

Co-authored-by: Robert Clabough <robert@clabough.tech>
This commit is contained in:
AgentScrubbles
2026-08-15 12:38:25 +10:00
committed by GitHub
co-authored by Robert Clabough
parent 380e3a50b4
commit 12c81eb1ac
2 changed files with 26 additions and 6 deletions
+4
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);
+22 -6
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,
@@ -388,9 +388,14 @@ pub fn run() {
.menu(&menu)
.on_menu_event(|app, event| match event.id.as_ref() {
"open" => {
app.webview_windows()
.get("frontend")
.expect("Failed to get webview")
#[cfg(target_os = "linux")]
{
// Resume webview rendering after showing
app_emit!(app, "window_visibility_change", ());
}
app.get_window("main")
.expect("Failed to get main window")
.show()
.expect("Failed to show window");
}
@@ -449,7 +454,13 @@ pub fn run() {
.on_window_event(|window, event| {
if let WindowEvent::CloseRequested { api, .. } = event {
run_on_tray(|| {
window.hide().expect("Failed to close window in tray");
// Pause webview rendering before hiding to prevent idle CPU usage
#[cfg(target_os = "linux")]
{
let _ = window.app_handle().emit("window_visibility_change", ());
}
window.hide().expect("Failed to hide window in tray");
api.prevent_close();
});
}
@@ -458,7 +469,12 @@ pub fn run() {
.expect("error while running tauri application");
app.run(|_app_handle, event| {
if let RunEvent::ExitRequested { code, api, .. } = event {
if let RunEvent::ExitRequested {
code,
api,
..
} = event
{
run_on_tray(|| {
if code.is_none() {
api.prevent_exit();