diff --git a/src-tauri/tauri-plugin-plugin-runtime/src/lib.rs b/src-tauri/tauri-plugin-plugin-runtime/src/lib.rs index 1d922e89..3281672f 100644 --- a/src-tauri/tauri-plugin-plugin-runtime/src/lib.rs +++ b/src-tauri/tauri-plugin-plugin-runtime/src/lib.rs @@ -1,7 +1,7 @@ extern crate core; -use log::info; use crate::manager::PluginManager; +use log::info; use tauri::plugin::{Builder, TauriPlugin}; use tauri::{Manager, RunEvent, Runtime, State}; use tokio::sync::Mutex; @@ -24,11 +24,12 @@ pub fn init() -> TauriPlugin { }) }) .on_event(|app, e| match e { - RunEvent::ExitRequested { code, .. } => { + // TODO: Also exit when app is force-quit (eg. cmd+r in IntelliJ runner) + RunEvent::Exit => { tauri::async_runtime::block_on(async move { - info!("Exiting plugin runtime due to app exit {:?}", code); + info!("Exiting plugin runtime due to app exit"); let manager: State> = app.state(); - manager.lock().await.cleanup(); + manager.lock().await.cleanup().await; }); } _ => {} diff --git a/src-tauri/tauri-plugin-plugin-runtime/src/manager.rs b/src-tauri/tauri-plugin-plugin-runtime/src/manager.rs index 4825b3c2..ae46e598 100644 --- a/src-tauri/tauri-plugin-plugin-runtime/src/manager.rs +++ b/src-tauri/tauri-plugin-plugin-runtime/src/manager.rs @@ -1,3 +1,4 @@ +use std::time::Duration; use log::{debug, info}; use tauri::{AppHandle, Manager, Runtime}; use tokio::sync::watch::Sender; @@ -30,8 +31,10 @@ impl PluginManager { PluginManager { client, kill_tx } } - pub fn cleanup(&mut self) { + pub async fn cleanup(&mut self) { self.kill_tx.send_replace(true); + // Give it a sec to get the tx and kill + tokio::time::sleep(Duration::from_millis(500)).await; } pub async fn run_import(&mut self, data: &str) -> Result { diff --git a/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs b/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs index 67e2021e..f3cfc914 100644 --- a/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs +++ b/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs @@ -75,6 +75,7 @@ pub async fn node_start( // Check on child tokio::spawn(async move { loop { + // Small sleep so we don't spin lock the CPU tokio::time::sleep(Duration::from_millis(50)).await; if let Ok(Some(status)) = child.try_wait() { error!("Plugin runtime exited status={}", status);