mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 08:11:24 +02:00
Fix killing command on Windows
This commit is contained in:
@@ -2,6 +2,7 @@ extern crate core;
|
|||||||
|
|
||||||
use crate::manager::PluginManager;
|
use crate::manager::PluginManager;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use std::process::exit;
|
||||||
use tauri::plugin::{Builder, TauriPlugin};
|
use tauri::plugin::{Builder, TauriPlugin};
|
||||||
use tauri::{Manager, RunEvent, Runtime, State};
|
use tauri::{Manager, RunEvent, Runtime, State};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
@@ -25,11 +26,13 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|||||||
})
|
})
|
||||||
.on_event(|app, e| match e {
|
.on_event(|app, e| match e {
|
||||||
// TODO: Also exit when app is force-quit (eg. cmd+r in IntelliJ runner)
|
// 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 {
|
tauri::async_runtime::block_on(async move {
|
||||||
info!("Exiting plugin runtime due to app exit");
|
info!("Exiting plugin runtime due to app exit");
|
||||||
let manager: State<Mutex<PluginManager>> = app.state();
|
let manager: State<Mutex<PluginManager>> = app.state();
|
||||||
manager.lock().await.cleanup().await;
|
manager.lock().await.cleanup().await;
|
||||||
|
exit(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
|
use std::time::Duration;
|
||||||
use tauri::{AppHandle, Manager, Runtime};
|
use tauri::{AppHandle, Manager, Runtime};
|
||||||
use tokio::sync::watch::Sender;
|
use tokio::sync::watch::Sender;
|
||||||
use tonic::transport::Channel;
|
use tonic::transport::Channel;
|
||||||
@@ -32,6 +33,9 @@ impl PluginManager {
|
|||||||
|
|
||||||
pub async fn cleanup(&mut self) {
|
pub async fn cleanup(&mut self) {
|
||||||
self.kill_tx.send_replace(true);
|
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> {
|
pub async fn run_import(&mut self, data: &str) -> Result<HookResponse, String> {
|
||||||
|
|||||||
@@ -55,15 +55,16 @@ pub async fn node_start<R: Runtime>(
|
|||||||
plugin_runtime_main,
|
plugin_runtime_main,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (_, child) = app
|
let cmd = app
|
||||||
.shell()
|
.shell()
|
||||||
.sidecar("yaaknode")
|
.sidecar("yaaknode")
|
||||||
.expect("yaaknode not found")
|
.expect("yaaknode not found")
|
||||||
.env("YAAK_GRPC_PORT_FILE_PATH", port_file_path.clone())
|
.env("YAAK_GRPC_PORT_FILE_PATH", port_file_path.clone())
|
||||||
.env("YAAK_PLUGINS_DIR", plugins_dir)
|
.env("YAAK_PLUGINS_DIR", plugins_dir)
|
||||||
.args(&[plugin_runtime_main])
|
.args(&[plugin_runtime_main]);
|
||||||
.spawn()
|
|
||||||
.expect("yaaknode failed to start");
|
println!("Waiting on plugin runtime");
|
||||||
|
let (_, child) = cmd.spawn().expect("yaaknode failed to start");
|
||||||
|
|
||||||
let mut kill_rx = kill_rx.clone();
|
let mut kill_rx = kill_rx.clone();
|
||||||
|
|
||||||
@@ -75,6 +76,7 @@ pub async fn node_start<R: Runtime>(
|
|||||||
.expect("Kill channel errored");
|
.expect("Kill channel errored");
|
||||||
info!("Killing plugin runtime");
|
info!("Killing plugin runtime");
|
||||||
child.kill().expect("Failed to kill plugin runtime");
|
child.kill().expect("Failed to kill plugin runtime");
|
||||||
|
info!("Killed plugin runtime");
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user