From 510a886b080fdb1172c6922a6ad85c9d0b0a84f5 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sun, 16 Aug 2020 18:56:07 +0200 Subject: [PATCH] Fix console showing on Windows when using Form extension --- native/libwinbridge/bridge.cpp | 2 +- packager.py | 2 +- src/extension/script.rs | 2 +- src/extension/shell.rs | 2 +- src/extension/utils.rs | 14 -------------- src/process.rs | 2 +- src/ui/modulo/form.rs | 1 - src/ui/modulo/mod.rs | 13 +++++++------ src/utils.rs | 14 ++++++++++++++ 9 files changed, 26 insertions(+), 26 deletions(-) delete mode 100644 src/ui/modulo/form.rs diff --git a/native/libwinbridge/bridge.cpp b/native/libwinbridge/bridge.cpp index 4aa279f..55d9567 100644 --- a/native/libwinbridge/bridge.cpp +++ b/native/libwinbridge/bridge.cpp @@ -745,7 +745,7 @@ int32_t start_daemon_process() { NULL, NULL, FALSE, - DETACHED_PROCESS, + DETACHED_PROCESS | CREATE_NO_WINDOW, NULL, NULL, &si, diff --git a/packager.py b/packager.py index af3fc54..fa34dd0 100644 --- a/packager.py +++ b/packager.py @@ -133,7 +133,7 @@ def build_windows(package_info): include_list.append("Source: \""+dll+"\"; DestDir: \"{app}\"; Flags: ignoreversion") print("Including modulo") - include_list.append("Source: \""+modulo_target_file+"\"; DestDir: \"{app}\"; Flags: ignoreversion") + include_list.append("Source: \""+os.path.abspath(modulo_target_file)+"\"; DestDir: \"{app}\"; Flags: ignoreversion") include = "\r\n".join(include_list) diff --git a/src/extension/script.rs b/src/extension/script.rs index 7261ed2..3a68a10 100644 --- a/src/extension/script.rs +++ b/src/extension/script.rs @@ -102,7 +102,7 @@ impl super::Extension for ScriptExtension { let mut command = Command::new(&str_args[0]); // Set the OS-specific flags - super::utils::set_command_flags(&mut command); + crate::utils::set_command_flags(&mut command); // Inject the $CONFIG variable command.env("CONFIG", crate::context::get_config_dir()); diff --git a/src/extension/shell.rs b/src/extension/shell.rs index 3beac0b..fd0f43a 100644 --- a/src/extension/shell.rs +++ b/src/extension/shell.rs @@ -81,7 +81,7 @@ impl Shell { }; // Set the OS-specific flags - super::utils::set_command_flags(&mut command); + crate::utils::set_command_flags(&mut command); // Inject the $CONFIG variable command.env("CONFIG", crate::context::get_config_dir()); diff --git a/src/extension/utils.rs b/src/extension/utils.rs index 0844cc4..fcf5bac 100644 --- a/src/extension/utils.rs +++ b/src/extension/utils.rs @@ -1,6 +1,5 @@ use crate::extension::ExtensionResult; use std::collections::HashMap; -use std::process::Command; pub fn convert_to_env_variables( original_vars: &HashMap, @@ -25,19 +24,6 @@ pub fn convert_to_env_variables( output } -#[cfg(target_os = "windows")] -pub fn set_command_flags(command: &mut Command) { - use std::os::windows::process::CommandExt; - // Avoid showing the shell window - // See: https://github.com/federico-terzi/espanso/issues/249 - command.creation_flags(0x08000000); -} - -#[cfg(not(target_os = "windows"))] -pub fn set_command_flags(command: &mut Command) { - // NOOP on Linux and macOS -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/process.rs b/src/process.rs index 7a03222..660abb0 100644 --- a/src/process.rs +++ b/src/process.rs @@ -25,7 +25,7 @@ use std::process::{Child, Command, Stdio}; pub fn spawn_process(cmd: &str, args: &Vec) -> io::Result { use std::os::windows::process::CommandExt; Command::new(cmd) - .creation_flags(0x00000008) // Detached Process + .creation_flags(0x08000008) // Detached Process without window .args(args) .spawn() } diff --git a/src/ui/modulo/form.rs b/src/ui/modulo/form.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/ui/modulo/form.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/ui/modulo/mod.rs b/src/ui/modulo/mod.rs index 0bf3543..5f306ac 100644 --- a/src/ui/modulo/mod.rs +++ b/src/ui/modulo/mod.rs @@ -3,8 +3,6 @@ use log::{error, info}; use std::io::{Error, Write}; use std::process::{Child, Command, Output}; -pub mod form; - pub struct ModuloManager { modulo_path: Option, } @@ -72,12 +70,15 @@ impl ModuloManager { } if let Some(ref modulo_path) = self.modulo_path { - let child = Command::new(modulo_path) - .args(args) + let mut command = Command::new(modulo_path); + command.args(args) .stdin(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::piped()) - .spawn(); + .stderr(std::process::Stdio::piped()); + + crate::utils::set_command_flags(&mut command); + + let child = command.spawn(); match child { Ok(mut child) => { diff --git a/src/utils.rs b/src/utils.rs index e619c8c..bea9fe2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -20,6 +20,7 @@ use std::error::Error; use std::fs::create_dir; use std::path::Path; +use std::process::Command; pub fn copy_dir(source_dir: &Path, dest_dir: &Path) -> Result<(), Box> { for entry in std::fs::read_dir(source_dir)? { @@ -40,6 +41,19 @@ pub fn copy_dir(source_dir: &Path, dest_dir: &Path) -> Result<(), Box Ok(()) } +#[cfg(target_os = "windows")] +pub fn set_command_flags(command: &mut Command) { + use std::os::windows::process::CommandExt; + // Avoid showing the shell window + // See: https://github.com/federico-terzi/espanso/issues/249 + command.creation_flags(0x08000000); +} + +#[cfg(not(target_os = "windows"))] +pub fn set_command_flags(command: &mut Command) { + // NOOP on Linux and macOS +} + #[cfg(test)] mod tests { use super::*;