diff --git a/docs/config.md b/docs/config.md index cc2e81a..d7d2b3f 100644 --- a/docs/config.md +++ b/docs/config.md @@ -53,9 +53,18 @@ If none are set then the `PYAPP_EXEC_MODULE` option will default to the value of ## Graphical user interface (GUI) -If you are packaging for windows on windows and your python execution calls a GUI, you can set `PYAPP_IS_GUI` to `true` or `1`. This will use `pythonw.exe` instead of `python.exe` to execute the application. If a GUI is run with `python.exe` on Windows, a console window will appear alongside the GUI. Details can be found [here](https://docs.python.org/3/using/windows.html#python-application). +If you are packaging a GUI, you can set `PYAPP_IS_GUI` to `true` or `1`. -Even when you set `PYAPP_IS_GUI` to `1`, you can still run the application from the command line. Furthermore, PyApp specific functions (e.g., installation and setup) will still display a console window with status messages. Note however that running a GUI application with `pythonw.exe` means that all `stdout` and `stderr` output will be discarded. +On windows, this will use `pythonw.exe` instead of `python.exe` to execute the application, which avoids a console window from appearing. +Note that running a GUI application with `pythonw.exe` means that all `stdout` and `stderr` output from your GUI will be discarded. + +On unix-like systems, `python` will be used for the execution. +PyApp will run your GUI by spawning a new process, such that the console window that calls the command terminates after successful spawning. + +!!!note + On macos, the console by default does not automatically close when processes have terminated. Thus, the console will stay open after the GUI is started, however, can be closed manually without interferring with the GUI. The default console behavior can be changed in the user settings to close after the last process terminated successfully, see, e.g., [here](https://stackoverflow.com/questions/5560167/osx-how-to-auto-close-terminal-window-after-the-exit-command-executed). + +Even when you set `PYAPP_IS_GUI` to `1`, you can still run the application from the command line. Furthermore, PyApp specific functions (e.g., installation and setup) will still display a console window with status messages. ## Python distribution diff --git a/src/app.rs b/src/app.rs index 898148b..51e09a1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -186,7 +186,6 @@ pub fn pip_external() -> bool { env!("PYAPP_PIP_EXTERNAL") == "1" } -#[cfg(windows)] pub fn app_is_gui() -> bool { env!("PYAPP_IS_GUI") == "1" } diff --git a/src/embed/project b/src/embed/project index e69de29..ab8fcec 100644 Binary files a/src/embed/project and b/src/embed/project differ diff --git a/src/process.rs b/src/process.rs index 3a007e7..7577d49 100644 --- a/src/process.rs +++ b/src/process.rs @@ -1,16 +1,13 @@ use std::io::Read; #[cfg(unix)] use std::os::unix::process::CommandExt; -#[cfg(windows)] +// #[cfg(windows)] use std::process::exit; use std::process::{Command, ExitStatus}; use anyhow::Result; -use crate::terminal; - -#[cfg(windows)] -use crate::app; +use crate::{app, terminal}; pub fn wait_for(mut command: Command, message: String) -> Result<(ExitStatus, String)> { let (mut reader, writer_stdout) = os_pipe::pipe()?; @@ -35,25 +32,28 @@ pub fn wait_for(mut command: Command, message: String) -> Result<(ExitStatus, St #[cfg(unix)] pub fn exec(mut command: Command) -> Result<()> { - Err(command.exec().into()) + if app::app_is_gui() { + exec_gui(command) + } else { + Err(command.exec().into()) + } } #[cfg(windows)] pub fn exec(mut command: Command) -> Result<()> { if app::app_is_gui() { - let mut child = command.spawn()?; - match child.try_wait() { - Ok(Some(status)) => { - exit(status.code().unwrap_or(1)); - } - Ok(None) => { - // The child is still running - Ok(()) - } - Err(e) => Err(e.into()), - } + exec_gui(command) } else { let status = command.status()?; exit(status.code().unwrap_or(1)); } } + +fn exec_gui(mut command: Command) -> Result<()> { + let mut child = command.spawn()?; + match child.try_wait() { + Ok(Some(status)) => exit(status.code().unwrap_or(1)), + Ok(None) => Ok(()), // The child is still running + Err(e) => Err(e.into()), + } +}