From 15c798381bd69ee17aba44db0c60025370d6ce78 Mon Sep 17 00:00:00 2001 From: Meadowsys Date: Mon, 22 May 2023 06:14:07 -0700 Subject: [PATCH] make backend on app exit termination work (#9) --- frontend/src-tauri/src/main.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/frontend/src-tauri/src/main.rs b/frontend/src-tauri/src/main.rs index 24bfd57..5a9ae0b 100644 --- a/frontend/src-tauri/src/main.rs +++ b/frontend/src-tauri/src/main.rs @@ -9,7 +9,7 @@ use std::fs; use std::path::PathBuf; use dialog::DialogBox; -use tauri::{AppHandle, Manager, Runtime, State, WindowEvent}; +use tauri::{AppHandle, Manager, RunEvent, Runtime, State}; use tauri::api::process::{Command, CommandChild, CommandEvent}; fn main() { @@ -39,25 +39,25 @@ fn main() { .expected(&app.handle(), "Failed to start child process"); Ok(()) }) - .on_window_event(move |event| match event.event() { - WindowEvent::Destroyed => { - let state: State = event.window().state(); - terminate_backend(&event.window().app_handle(), state + .invoke_handler(tauri::generate_handler![ + start_server, + stop_server, + restart_server + ]) + .build(tauri::generate_context!()) + .expect("error while running tauri application") + .run(|apphandle, event| match event { + RunEvent::Exit => { + let state: State = apphandle.state(); + terminate_backend(apphandle, state .mutex .lock() .unwrap() .borrow_mut(), - ).expected(&event.window().app_handle(), "Failed to terminate child process"); + ).expected(&apphandle, "Failed to terminate child process"); } _ => {} }) - .invoke_handler(tauri::generate_handler![ - start_server, - stop_server, - restart_server - ]) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); } fn send_console(app: &AppHandle, message: impl Into) {