Fix killing command on Windows

This commit is contained in:
Gregory Schier
2024-07-28 15:40:19 -07:00
parent 087a1e5ea1
commit 42fd7cb21e
3 changed files with 14 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ extern crate core;
use crate::manager::PluginManager;
use log::info;
use std::process::exit;
use tauri::plugin::{Builder, TauriPlugin};
use tauri::{Manager, RunEvent, Runtime, State};
use tokio::sync::Mutex;
@@ -25,11 +26,13 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
})
.on_event(|app, e| match e {
// TODO: Also exit when app is force-quit (eg. cmd+r in IntelliJ runner)
RunEvent::Exit => {
RunEvent::ExitRequested { api, .. } => {
api.prevent_exit();
tauri::async_runtime::block_on(async move {
info!("Exiting plugin runtime due to app exit");
let manager: State<Mutex<PluginManager>> = app.state();
manager.lock().await.cleanup().await;
exit(0);
});
}
_ => {}

View File

@@ -1,4 +1,5 @@
use log::{debug, info};
use std::time::Duration;
use tauri::{AppHandle, Manager, Runtime};
use tokio::sync::watch::Sender;
use tonic::transport::Channel;
@@ -32,6 +33,9 @@ impl PluginManager {
pub async fn cleanup(&mut self) {
self.kill_tx.send_replace(true);
// Give it a bit of time to kill
tokio::time::sleep(Duration::from_millis(500)).await;
}
pub async fn run_import(&mut self, data: &str) -> Result<HookResponse, String> {

View File

@@ -55,15 +55,16 @@ pub async fn node_start<R: Runtime>(
plugin_runtime_main,
);
let (_, child) = app
let cmd = app
.shell()
.sidecar("yaaknode")
.expect("yaaknode not found")
.env("YAAK_GRPC_PORT_FILE_PATH", port_file_path.clone())
.env("YAAK_PLUGINS_DIR", plugins_dir)
.args(&[plugin_runtime_main])
.spawn()
.expect("yaaknode failed to start");
.args(&[plugin_runtime_main]);
println!("Waiting on plugin runtime");
let (_, child) = cmd.spawn().expect("yaaknode failed to start");
let mut kill_rx = kill_rx.clone();
@@ -75,6 +76,7 @@ pub async fn node_start<R: Runtime>(
.expect("Kill channel errored");
info!("Killing plugin runtime");
child.kill().expect("Failed to kill plugin runtime");
info!("Killed plugin runtime");
return;
});