Skip to content

Commit

Permalink
Spawn player with CREATE_BREAKAWAY_FROM_JOB on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ryze312 committed Oct 21, 2023
1 parent 4aa4ca5 commit b0595f1
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit b0595f1

Please sign in to comment.