fix(windows): don't open terminal windows when runnings commands

This commit is contained in:
uku 2025-07-11 10:20:45 +02:00
parent 39ce297e17
commit 7bbc5e0393
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o

View file

@ -14,6 +14,40 @@ use tokio::{
use crate::ProgressMessage;
trait CommandExt {
fn create_no_window(&mut self) -> &mut Self;
}
impl CommandExt for Command {
#[cfg(windows)]
fn create_no_window(&mut self) -> &mut Self {
use std::os::windows::process::CommandExt as _;
// https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags#flags
self.creation_flags(0x0800_0000)
}
#[cfg(not(windows))]
fn create_no_window(&mut self) -> &mut Self {
self
}
}
impl CommandExt for std::process::Command {
#[cfg(windows)]
fn create_no_window(&mut self) -> &mut Self {
use std::os::windows::process::CommandExt as _;
// https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags#flags
self.creation_flags(0x0800_0000)
}
#[cfg(not(windows))]
fn create_no_window(&mut self) -> &mut Self {
self
}
}
#[derive(serde::Deserialize)]
struct FfprobeOut {
streams: Vec<StreamInfo>,
@ -59,10 +93,12 @@ impl From<String> for Codec {
pub fn check() -> Result<()> {
std::process::Command::new("ffmpeg")
.create_no_window()
.output()
.context("could not find ffmpeg")?;
std::process::Command::new("ffprobe")
.create_no_window()
.output()
.context("could not find ffprobe")?;
@ -81,6 +117,7 @@ pub async fn get_video_meta(path: &Path) -> Result<VideoMeta> {
])
.arg(path)
.stdout(Stdio::piped())
.create_no_window()
.output()
.await?;
@ -151,6 +188,7 @@ pub async fn convert_video(
.args(["-y", "-loglevel", "error", "-progress", "-", "-nostats"])
.arg(&out_path)
.stdout(Stdio::piped())
.create_no_window()
.spawn()?;
let stdout = child.stdout.take().unwrap();