Fix console showing on Windows when using Form extension

This commit is contained in:
Federico Terzi 2020-08-16 18:56:07 +02:00
parent 4ad96eb2f3
commit 510a886b08
9 changed files with 26 additions and 26 deletions

View File

@ -745,7 +745,7 @@ int32_t start_daemon_process() {
NULL,
NULL,
FALSE,
DETACHED_PROCESS,
DETACHED_PROCESS | CREATE_NO_WINDOW,
NULL,
NULL,
&si,

View File

@ -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)

View File

@ -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());

View File

@ -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());

View File

@ -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<String, ExtensionResult>,
@ -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::*;

View File

@ -25,7 +25,7 @@ use std::process::{Child, Command, Stdio};
pub fn spawn_process(cmd: &str, args: &Vec<String>) -> io::Result<Child> {
use std::os::windows::process::CommandExt;
Command::new(cmd)
.creation_flags(0x00000008) // Detached Process
.creation_flags(0x08000008) // Detached Process without window
.args(args)
.spawn()
}

View File

@ -1 +0,0 @@

View File

@ -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<String>,
}
@ -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) => {

View File

@ -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<dyn Error>> {
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<dyn Error>
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::*;