From fcc1f76d7069082cc13176f9c27a65c2a3ebfe48 Mon Sep 17 00:00:00 2001 From: Alexandr Bogomiakov Date: Thu, 24 Jul 2025 02:36:21 +0300 Subject: [PATCH] Fixed windows start console --- src/gui/common/settings.rs | 2 +- src/gui/tray/app.rs | 1 - src/main.rs | 88 +++++++++++++++++++++++--------------- 3 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/gui/common/settings.rs b/src/gui/common/settings.rs index fc7f6e5..47af614 100644 --- a/src/gui/common/settings.rs +++ b/src/gui/common/settings.rs @@ -115,7 +115,7 @@ pub async fn perform_sync(settings: &KhmSettings) -> Result std::io::Result<()> { let args = Args::parse(); + // Hide console on Windows if daemon flag is set + if args.daemon { + #[cfg(target_os = "windows")] + { + extern "system" { + fn FreeConsole() -> i32; + } + unsafe { + FreeConsole(); + } + } + } + // Settings UI mode - just show settings window and exit if args.settings_ui { + // Always hide console for settings window + #[cfg(target_os = "windows")] + { + extern "system" { + fn FreeConsole() -> i32; + } + unsafe { + FreeConsole(); + } + } + #[cfg(feature = "gui")] { info!("Running settings UI window"); @@ -172,39 +203,26 @@ async fn main() -> std::io::Result<()> { } } - // GUI mode has priority - if args.gui { + // Check if we should run GUI mode (default when no server/client args) + if !args.server && (args.host.is_none() || args.flow.is_none()) { info!("Running in GUI mode"); - if let Err(e) = gui::run_gui().await { - error!("Failed to run GUI: {}", e); + #[cfg(feature = "gui")] + { + if let Err(e) = gui::run_gui().await { + error!("Failed to run GUI: {}", e); + } + } + #[cfg(not(feature = "gui"))] + { + error!("GUI features not compiled. Install system dependencies and rebuild with --features gui"); + return Err(std::io::Error::new( + std::io::ErrorKind::Unsupported, + "GUI features not compiled", + )); } return Ok(()); } - // Check if we have the minimum required arguments for server/client mode - if !args.server && !args.gui && (args.host.is_none() || args.flow.is_none()) { - // Neither server mode nor client mode nor GUI mode properly configured - eprintln!("Error: You must specify either server mode (--server), client mode (--host and --flow), or GUI mode (--gui)"); - eprintln!(); - eprintln!("Examples:"); - eprintln!( - " Server mode: {} --server --db-user admin --db-password pass --flows work,home", - env!("CARGO_PKG_NAME") - ); - eprintln!( - " Client mode: {} --host https://khm.example.com --flow work", - env!("CARGO_PKG_NAME") - ); - eprintln!(" GUI mode: {} --gui", env!("CARGO_PKG_NAME")); - eprintln!( - " Settings window: {} --gui --settings-ui", - env!("CARGO_PKG_NAME") - ); - eprintln!(); - eprintln!("Use --help for more information."); - std::process::exit(1); - } - if args.server { info!("Running in server mode"); if let Err(e) = server::run_server(args).await {