feat(app): hide window instead of closing

Instead of closing the window, this commit changes the event listener so that it simply hides the window instead. This allows for near-instant re-opening of the window, as well as state preservation.
This commit is contained in:
ByteAtATime 2025-06-25 14:18:06 -07:00
parent 3cb7f984b2
commit 9d73ac0a23
No known key found for this signature in database

View file

@ -175,7 +175,7 @@ fn setup_input_listener(app: &tauri::AppHandle) {
#[cfg_attr(mobile, tauri::mobile_entry_point)] #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() { pub fn run() {
tauri::Builder::default() let app = tauri::Builder::default()
.plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_http::init()) .plugin(tauri_plugin_http::init())
@ -271,6 +271,19 @@ pub fn run() {
Ok(()) Ok(())
}) })
.run(tauri::generate_context!()) .build(tauri::generate_context!()).unwrap();
.expect("error while running tauri application");
app.run(|app, event| {
if let tauri::RunEvent::WindowEvent {
event: tauri::WindowEvent::CloseRequested { api, .. },
..
} = event
{
api.prevent_close();
app.get_webview_window("main")
.unwrap()
.hide()
.expect("To hide the window");
}
});
} }