diff options
author | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2021-06-14 09:47:02 +0200 |
---|---|---|
committer | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2021-06-14 09:47:02 +0200 |
commit | bbf591f23b63d35875c9a8c654fb999b7c6742d4 (patch) | |
tree | 8a6d1bf916e59f62d6e6ed9ac80c9797a7f42b63 | |
parent | e3814db7afa99c3d93654b43d17ffc91dac79ce3 (diff) |
ipc: Invoke GnuPG in background without flashing terminals.
See relevant MR on sequoia-octopus-lib:
https://gitlab.com/sequoia-pgp/sequoia-octopus-librnp/-/merge_requests/42
-rw-r--r-- | ipc/src/gnupg.rs | 7 | ||||
-rw-r--r-- | ipc/src/lib.rs | 22 |
2 files changed, 25 insertions, 4 deletions
diff --git a/ipc/src/gnupg.rs b/ipc/src/gnupg.rs index 1d6b49bf..f008d012 100644 --- a/ipc/src/gnupg.rs +++ b/ipc/src/gnupg.rs @@ -7,7 +7,6 @@ use std::convert::TryFrom; use std::ffi::OsStr; use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; -use std::process::Command; use futures::{Future, Stream}; @@ -132,7 +131,9 @@ impl Context { Mode::Windows => "--windows", Mode::Unix => "--unix", }; - Command::new("cygpath").arg(conversion_type).arg(path.as_ref()) + crate::new_background_command("cygpath") + .arg(conversion_type) + .arg(path.as_ref()) .output() .map_err(Into::into) .and_then(|out| @@ -162,7 +163,7 @@ impl Context { let nl = |&c: &u8| c as char == '\n'; let colon = |&c: &u8| c as char == ':'; - let mut gpgconf = Command::new("gpgconf"); + let mut gpgconf = crate::new_background_command("gpgconf"); if let Some(homedir) = homedir { gpgconf.arg("--homedir").arg(homedir); diff --git a/ipc/src/lib.rs b/ipc/src/lib.rs index dbc9f965..b0bb3dee 100644 --- a/ipc/src/lib.rs +++ b/ipc/src/lib.rs @@ -245,7 +245,7 @@ impl Descriptor { } fn fork(&self, listener: TcpListener) -> Result<()> { - let mut cmd = Command::new(&self.executable); + let mut cmd = new_background_command(&self.executable); cmd .arg("--home") .arg(self.ctx.home()) @@ -533,3 +533,23 @@ fn wsa_cleanup() { let _ = unsafe { winsock2::WSACleanup() }; } } + +pub(crate) fn new_background_command<S>(program: S) -> Command +where + S: AsRef<std::ffi::OsStr>, +{ + let command = Command::new(program); + + #[cfg(windows)] + let command = { + use std::os::windows::process::CommandExt; + + // see https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags + const CREATE_NO_WINDOW: u32 = 0x08000000; + let mut command = command; + command.creation_flags(CREATE_NO_WINDOW); + command + }; + + command +} |