Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): prevent from displaying cli window #1058

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
16 changes: 16 additions & 0 deletions src-tauri/src/external_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,22 @@ impl ExternalDependencies {
) -> Result<(), Error> {
info!(target: LOG_TARGET, "Installing missing dependency: {}", missing_dependency.display_name);
let installer_path = self.download_installer(&missing_dependency).await?;

#[cfg(target_os = "windows")]
use crate::consts::PROCESS_CREATION_NO_WINDOW;
#[cfg(target_os = "windows")]
let mut thread = tokio::process::Command::new(installer_path)
.creation_flags(PROCESS_CREATION_NO_WINDOW)
.spawn()
.map_err(|e| {
anyhow!(
"Failed to start installer for {}: {}",
missing_dependency.display_name,
e
)
})?;

#[cfg(not(target_os = "windows"))]
let mut thread = tokio::process::Command::new(installer_path)
.spawn()
.map_err(|e| {
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/process_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ pub(crate) trait ProcessAdapter {

fn pid_file_name(&self) -> &str;

fn kill_previous_instances(&self, base_folder: PathBuf) -> Result<(), Error> {
async fn kill_previous_instances(&self, base_folder: PathBuf) -> Result<(), Error> {
info!(target: LOG_TARGET, "Killing previous instances of {}", self.name());
match fs::read_to_string(base_folder.join(self.pid_file_name())) {
Ok(pid) => match pid.trim().parse::<i32>() {
Ok(pid) => {
warn!(target: LOG_TARGET, "{} process did not shut down cleanly: {} pid file was created", pid, self.pid_file_name());
kill_process(pid)?;
kill_process(pid).await?;
}
Err(e) => {
let error_msg =
Expand Down
25 changes: 14 additions & 11 deletions src-tauri/src/process_killer.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#[cfg(target_os = "windows")]
const LOG_TARGET: &str = "tari::universe::process_killer";
use anyhow::Result;

pub fn kill_process(pid: i32) -> Result<(), anyhow::Error> {
pub async fn kill_process(pid: i32) -> Result<(), anyhow::Error> {
#[cfg(target_os = "windows")]
{
use log::warn;
use std::process::Command;
let output = Command::new("taskkill")
.args(["/F", "/PID", &pid.to_string()])
.output()?;
if !output.status.success() {
warn!(target: LOG_TARGET, "Failed to kill process: {:?}", output);
}
use crate::consts::PROCESS_CREATION_NO_WINDOW;
use anyhow::Context;
let command = format!("taskkill /F /PID {}", pid);

let mut child = tokio::process::Command::new("cmd")
.arg("/C")
.arg(command)
.creation_flags(PROCESS_CREATION_NO_WINDOW)
.spawn()
.context(format!("Failed to start taskkill for PID {}: {}", pid, pid))?;

child.wait().await?;
}

#[cfg(not(target_os = "windows"))]
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/process_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<TAdapter: ProcessAdapter> ProcessWatcher<TAdapter> {
&mut self,
base_path: PathBuf,
) -> Result<(), anyhow::Error> {
self.adapter.kill_previous_instances(base_path)?;
self.adapter.kill_previous_instances(base_path).await?;
Ok(())
}

Expand Down
2 changes: 0 additions & 2 deletions src-tauri/src/xmrig_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ impl ProcessAdapter for XmrigAdapter {
log_dir: PathBuf,
binary_version_path: PathBuf,
) -> Result<(ProcessInstance, Self::StatusMonitor), anyhow::Error> {
self.kill_previous_instances(data_dir.clone())?;

let xmrig_shutdown = Shutdown::new();
let mut args = self
.node_connection
Expand Down