Skip to content

Commit 1c3aad8

Browse files
committed
Make absolutely sure subprocess is not killed
1 parent 2e02dfd commit 1c3aad8

File tree

3 files changed

+131
-6
lines changed

3 files changed

+131
-6
lines changed

Cargo.lock

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ edition = "2021"
77
serde = { version = "1.0.*", features = ["derive"] }
88
serde_json = { version = "1.0.*", features = ["preserve_order"] }
99

10+
[target.'cfg(windows)'.dependencies]
11+
windows = { version = "0.56", features = ["Win32_System_Threading"] }
12+
1013
[profile.dev-optimized]
1114
inherits = "dev"
1215
opt-level = 3

src/command.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,19 @@ impl Command {
9595
command.arg("--");
9696
command.arg(url);
9797

98-
// NOTE: On Windows, browser spawns process into a Job object.
99-
// NOTE: We need to detach player from the job, so it won't get killed after we're done,
100-
// NOTE: See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging#closing_the_native_app
98+
// NOTE: Make sure the subprocess is not killed.
99+
// See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging#closing_the_native_app
100+
101+
#[cfg(target_family = "unix")]
102+
{
103+
use std::os::unix::process::CommandExt;
104+
command.process_group(0);
105+
}
106+
101107
#[cfg(target_family = "windows")]
102108
{
103109
use std::os::windows::process::CommandExt;
104-
const CREATE_BREAKAWAY_FROM_JOB: u32 = 0x01000000;
105-
106-
command.creation_flags(CREATE_BREAKAWAY_FROM_JOB);
110+
command.creation_flags(windows::Win32::System::Threading::CREATE_BREAKAWAY_FROM_JOB.0);
107111
}
108112

109113
command.spawn()?;

0 commit comments

Comments
 (0)