nex_squid/src-tauri/src/process.rs

35 lines
1008 B
Rust

//! Child-process helpers for a GUI app.
//!
//! Every helper is spawned without a console window on Windows. The updater
//! also relies on the same hidden spawn path so a background download never
//! flashes a terminal over the main window.
use std::ffi::OsStr;
use std::process::{Command, Stdio};
#[cfg(target_os = "windows")]
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
#[cfg(target_os = "windows")]
const CREATE_NEW_PROCESS_GROUP: u32 = 0x0000_0200;
pub fn hidden(command: &mut Command) -> &mut Command {
#[cfg(target_os = "windows")]
{
use std::os::windows::process::CommandExt;
command.creation_flags(CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP);
}
#[cfg(not(target_os = "windows"))]
let _ = command;
command
}
pub fn command(program: impl AsRef<OsStr>) -> Command {
let mut command = Command::new(program);
command
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null());
hidden(&mut command);
command
}