Spawn player with CREATE_BREAKAWAY_FROM_JOB on Windows #6

Merged
ryze312 merged 1 commit from windows_launch_bug into main 2023-10-21 20:39:13 +02:00

View file

@ -70,12 +70,25 @@ impl Command {
} }
fn launch_mpv(command: String, args: Vec<String>, url: &str) -> Result<(), io::Error> { fn launch_mpv(command: String, args: Vec<String>, url: &str) -> Result<(), io::Error> {
process::Command::new(command) let mut command = process::Command::new(command);
.stdout(process::Stdio::null())
.stderr(process::Stdio::null()) command.stdout(process::Stdio::null());
.args(args) command.stderr(process::Stdio::null());
.arg(url) command.args(args);
.spawn()?; 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(()) Ok(())
} }