From e600418da893c9ee0af3c961e1577d9b87182b2b Mon Sep 17 00:00:00 2001 From: FallenSigh Date: Sat, 13 Jun 2026 14:35:25 +0800 Subject: [PATCH] Detach GUI from terminal on linux, hide console on Windows --- crates/pipeview-gui/src/main.rs | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/pipeview-gui/src/main.rs b/crates/pipeview-gui/src/main.rs index 662f812..2c7eb38 100644 --- a/crates/pipeview-gui/src/main.rs +++ b/crates/pipeview-gui/src/main.rs @@ -1,3 +1,5 @@ +#![cfg_attr(windows, windows_subsystem = "windows")] + mod app; mod app_state; mod buffers; @@ -9,7 +11,41 @@ mod ui_fonts; use pipeview_client::SessionManager; +/// On Linux, when launched from a file manager, a terminal emulator may be spawned +/// to run this binary. We re-spawn ourselves detached so the terminal can close +/// while the GUI window persists. +#[cfg(target_os = "linux")] +fn ensure_detached() { + use std::os::unix::process::CommandExt; + use std::process; + + if std::env::var("PIPEVIEW_DETACHED").is_ok() { + return; + } + + let exe = match std::env::current_exe() { + Ok(p) => p, + Err(_) => return, + }; + + let args: Vec = std::env::args().skip(1).collect(); + + let _ = process::Command::new(&exe) + .args(&args) + .env("PIPEVIEW_DETACHED", "1") + .stdin(process::Stdio::null()) + .stdout(process::Stdio::null()) + .stderr(process::Stdio::null()) + .process_group(0) + .spawn(); + + process::exit(0); +} + fn main() { + #[cfg(target_os = "linux")] + ensure_detached(); + tracing_subscriber::fmt() .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) .init();