Skip to content

Commit

Permalink
make backend on app exit termination work (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
meadowsys authored May 22, 2023
1 parent cbef206 commit 15c7983
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions frontend/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<ChildProcessState> = 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<ChildProcessState> = 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<R: Runtime>(app: &AppHandle<R>, message: impl Into<String>) {
Expand Down

0 comments on commit 15c7983

Please sign in to comment.