Spawn player with CREATE_BREAKAWAY_FROM_JOB on Windows

This commit is contained in:
Ryze 2023-10-21 20:55:31 +03:00
parent 4aa4ca5d8c
commit b0595f172d
Signed by: ryze
GPG key ID: 9B296C5CEAEAAAC1

View file

@ -70,12 +70,25 @@ impl Command {
}
fn launch_mpv(command: String, args: Vec<String>, url: &str) -> Result<(), io::Error> {
process::Command::new(command)
.stdout(process::Stdio::null())
.stderr(process::Stdio::null())
.args(args)
.arg(url)
.spawn()?;
let mut command = process::Command::new(command);
command.stdout(process::Stdio::null());
command.stderr(process::Stdio::null());
command.args(args);
command.arg(url);
// NOTE: On Windows, browser spawns process into a Job object.
// NOTE: We need to detach player from the job, so it won't get killed after we're done,
// NOTE: See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging#closing_the_native_app
#[cfg(target_family = "windows")]
{
use std::os::windows::process::CommandExt;
const CREATE_BREAKAWAY_FROM_JOB: u32 = 0x01000000;
command.creation_flags(CREATE_BREAKAWAY_FROM_JOB);
}
command.spawn()?;
Ok(())
}