Skip to content

Commit b0595f1

Browse files
committed
Spawn player with CREATE_BREAKAWAY_FROM_JOB on Windows
1 parent 4aa4ca5 commit b0595f1

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/command.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,25 @@ impl Command {
7070
}
7171

7272
fn launch_mpv(command: String, args: Vec<String>, url: &str) -> Result<(), io::Error> {
73-
process::Command::new(command)
74-
.stdout(process::Stdio::null())
75-
.stderr(process::Stdio::null())
76-
.args(args)
77-
.arg(url)
78-
.spawn()?;
73+
let mut command = process::Command::new(command);
74+
75+
command.stdout(process::Stdio::null());
76+
command.stderr(process::Stdio::null());
77+
command.args(args);
78+
command.arg(url);
79+
80+
// NOTE: On Windows, browser spawns process into a Job object.
81+
// NOTE: We need to detach player from the job, so it won't get killed after we're done,
82+
// NOTE: See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging#closing_the_native_app
83+
#[cfg(target_family = "windows")]
84+
{
85+
use std::os::windows::process::CommandExt;
86+
const CREATE_BREAKAWAY_FROM_JOB: u32 = 0x01000000;
87+
88+
command.creation_flags(CREATE_BREAKAWAY_FROM_JOB);
89+
}
90+
91+
command.spawn()?;
7992

8093
Ok(())
8194
}

0 commit comments

Comments
 (0)