diff --git a/crates/rhai_impl/src/updates/listen.rs b/crates/rhai_impl/src/updates/listen.rs index bd12259..a4c410f 100644 --- a/crates/rhai_impl/src/updates/listen.rs +++ b/crates/rhai_impl/src/updates/listen.rs @@ -20,7 +20,7 @@ use nix::{ }; use rhai::Map; use shared_utils::extract_props::*; -use std::process::{Command as synced_command, Stdio}; +use std::process::Stdio; use tokio::io::AsyncBufReadExt; use tokio::io::BufReader; use tokio::process::Command; @@ -30,6 +30,7 @@ use tokio::sync::watch; pub fn handle_listen( var_name: String, props: &Map, + shell: String, store: ReactiveVarStore, tx: tokio::sync::mpsc::UnboundedSender, ) { @@ -55,18 +56,7 @@ pub fn handle_listen( let (shutdown_tx, mut shutdown_rx) = watch::channel(false); SHUTDOWN_REGISTRY.lock().unwrap().push(shutdown_tx.clone()); - // Check Dash and prefer if dash is installed. - - let dash_installed: bool = synced_command::new("which") - .arg("dash") - .output() - .map(|o| o.status.success()) - .unwrap_or(false); - - let shell: &str = if dash_installed { "/bin/dash" } else { "/bin/sh" }; - // Task to catch SIGINT and SIGTERM - tokio::spawn({ let shutdown_tx = shutdown_tx.clone(); async move { @@ -87,7 +77,7 @@ pub fn handle_listen( tokio::spawn(async move { let mut child = unsafe { - Command::new(shell) + Command::new(&shell) .arg("-c") .arg(&cmd) // .kill_on_drop(true) diff --git a/crates/rhai_impl/src/updates/mod.rs b/crates/rhai_impl/src/updates/mod.rs index b376b7f..cb4d889 100644 --- a/crates/rhai_impl/src/updates/mod.rs +++ b/crates/rhai_impl/src/updates/mod.rs @@ -25,6 +25,7 @@ use std::sync::Mutex; use std::{collections::HashMap, sync::Arc, sync::RwLock}; use tokio::sync::mpsc::UnboundedSender; use tokio::sync::watch; +use std::process::Command; pub type ReactiveVarStore = Arc>>; pub static SHUTDOWN_REGISTRY: Lazy>>> = @@ -35,14 +36,23 @@ pub fn handle_state_changes( tx: UnboundedSender, store: ReactiveVarStore, ) { + // Check Dash and prefer if dash is installed. + let dash_installed: bool = Command::new("which") + .arg("dash") + .output() + .map(|o| o.status.success()) + .unwrap_or(false); + + let shell = if dash_installed { String::from("/bin/dash") } else { String::from("/bin/sh") }; + if let WidgetNode::Enter(children) = root_node { for child in children { match child { WidgetNode::Poll { var, props } => { - handle_poll(var.to_string(), props, store.clone(), tx.clone()); + handle_poll(var.to_string(), props, shell.clone(), store.clone(), tx.clone()); } WidgetNode::Listen { var, props } => { - handle_listen(var.to_string(), props, store.clone(), tx.clone()); + handle_listen(var.to_string(), props, shell.clone(), store.clone(), tx.clone()); } _ => {} } diff --git a/crates/rhai_impl/src/updates/poll.rs b/crates/rhai_impl/src/updates/poll.rs index ab28982..bf96c69 100644 --- a/crates/rhai_impl/src/updates/poll.rs +++ b/crates/rhai_impl/src/updates/poll.rs @@ -23,11 +23,10 @@ use tokio::process::Command; use tokio::sync::watch; use tokio::time::sleep; -use std::process::Command as synced_command; - pub fn handle_poll( var_name: String, props: &Map, + shell: String, store: ReactiveVarStore, tx: tokio::sync::mpsc::UnboundedSender, ) { @@ -57,19 +56,9 @@ pub fn handle_poll( let (shutdown_tx, mut shutdown_rx) = watch::channel(false); SHUTDOWN_REGISTRY.lock().unwrap().push(shutdown_tx.clone()); - // Check Dash and prefer if dash is installed. - - let dash_installed: bool = synced_command::new("which") - .arg("dash") - .output() - .map(|o| o.status.success()) - .unwrap_or(false); - - let shell: &str = if dash_installed { "/bin/dash" } else { "/bin/sh" }; - tokio::spawn(async move { // Spawn a persistent shell - let mut child = match Command::new(shell) + let mut child = match Command::new(&shell) .stdin(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()) .spawn()