From 9967bb993f52cd7f58715299cb1487410c7e6830 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Thu, 27 Jul 2023 10:46:48 +0800 Subject: [PATCH] more flexible for --get-id --- src/core_main.rs | 2 +- src/main.rs | 2 +- src/platform/windows.rs | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core_main.rs b/src/core_main.rs index cd972b25d..a55d2ec8d 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -102,7 +102,7 @@ pub fn core_main() -> Option> { } if args.len() > 0 && args[0] == "--version" { // not use my_println here, because check super use using this command, no dialog expected - println!("{}", crate::VERSION); + my_println!("{}", crate::VERSION); return None; } #[cfg(windows)] diff --git a/src/main.rs b/src/main.rs index e5c218ec4..2ab940d35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ #![cfg_attr( - all(not(debug_assertions), target_os = "windows"), + all(target_os = "windows"), windows_subsystem = "windows" )] diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 22ff64687..b790fa1a1 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -2301,16 +2301,30 @@ mod tests { pub fn message_box(text: &str) { let mut text = text.to_owned(); - if !text.ends_with("!") { + let nodialog = std::env::var("NO_DIALOG").unwrap_or_default() == "Y"; + if !text.ends_with("!") || nodialog { use arboard::Clipboard as ClipboardContext; match ClipboardContext::new() { Ok(mut ctx) => { ctx.set_text(&text).ok(); - text = format!("{}\n\nAbove text has been copied to clipboard", &text); + if !nodialog { + text = format!("{}\n\nAbove text has been copied to clipboard", &text); + } } _ => {} } } + if nodialog { + if std::env::var("PRINT_OUT").unwrap_or_default() == "Y" { + println!("{text}"); + } + if let Ok(x) = std::env::var("WRITE_TO_FILE") { + if !x.is_empty() { + allow_err!(std::fs::write(x, text)); + } + } + return; + } let text = text .encode_utf16() .chain(std::iter::once(0))