From 9ef756096374786737a80e1a4e30e8eea37908d7 Mon Sep 17 00:00:00 2001 From: MeexReay Date: Mon, 16 Jun 2025 04:18:11 +0300 Subject: [PATCH] add debug logs setting --- src/chat/config.rs | 5 ++++- src/chat/gui.rs | 19 ++++++++++++++----- src/chat/mod.rs | 6 ++++-- src/chat/styles/dark.css | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/chat/config.rs b/src/chat/config.rs index 44bd1ea..9f0e3f6 100644 --- a/src/chat/config.rs +++ b/src/chat/config.rs @@ -29,6 +29,7 @@ pub struct Config { #[serde(default)] pub wrac_enabled: bool, #[serde(default)] pub proxy: Option, #[serde(default = "default_true")] pub notifications_enabled: bool, + #[serde(default)] pub debug_logs: bool, } pub fn get_config_path() -> PathBuf { @@ -120,6 +121,7 @@ pub struct Args { #[arg(long)] pub notifications_enabled: Option, #[arg(long)] pub wrac_enabled: Option, #[arg(long)] pub proxy: Option, + #[arg(long)] pub debug_logs: bool, } impl Args { @@ -139,5 +141,6 @@ impl Args { if let Some(v) = self.commands_enabled { config.commands_enabled = v } if let Some(v) = self.notifications_enabled { config.notifications_enabled = v } if let Some(v) = self.wrac_enabled { config.wrac_enabled = v } + if self.debug_logs { config.debug_logs = true } } -} \ No newline at end of file +} diff --git a/src/chat/gui.rs b/src/chat/gui.rs index f78c453..55d1d58 100644 --- a/src/chat/gui.rs +++ b/src/chat/gui.rs @@ -173,6 +173,7 @@ fn open_settings(ctx: Arc, app: &Application) { let formatting_enabled_entry = gui_checkbox_setting!("Formatting Enabled", formatting_enabled, ctx, vbox); let commands_enabled_entry = gui_checkbox_setting!("Commands Enabled", commands_enabled, ctx, vbox); let notifications_enabled_entry = gui_checkbox_setting!("Notifications Enabled", notifications_enabled, ctx, vbox); + let debug_logs_entry = gui_checkbox_setting!("Debug Logs", debug_logs, ctx, vbox); let save_button = Button::builder() .label("Save") @@ -197,6 +198,7 @@ fn open_settings(ctx: Arc, app: &Application) { #[weak] notifications_enabled_entry, #[weak] wrac_enabled_entry, #[weak] proxy_entry, + #[weak] debug_logs_entry, move |_| { let config = Config { host: host_entry.text().to_string(), @@ -241,6 +243,7 @@ fn open_settings(ctx: Arc, app: &Application) { formatting_enabled: formatting_enabled_entry.is_active(), commands_enabled: commands_enabled_entry.is_active(), notifications_enabled: notifications_enabled_entry.is_active(), + debug_logs: debug_logs_entry.is_active(), proxy: { let proxy = proxy_entry.text().to_string(); @@ -554,8 +557,10 @@ fn build_ui(ctx: Arc, app: &Application) -> UiModel { )); if let Err(e) = on_send_message(ctx.clone(), &text_entry.text()) { - let msg = format!("Send message error: {}", e.to_string()).to_string(); - add_chat_message(ctx.clone(), msg); + if ctx.config(|o| o.debug_logs) { + let msg = format!("Send message error: {}", e.to_string()).to_string(); + add_chat_message(ctx.clone(), msg); + } } } )); @@ -573,8 +578,10 @@ fn build_ui(ctx: Arc, app: &Application) -> UiModel { )); if let Err(e) = on_send_message(ctx.clone(), &text_entry.text()) { - let msg = format!("Send message error: {}", e.to_string()).to_string(); - add_chat_message(ctx.clone(), msg); + if ctx.config(|o| o.debug_logs) { + let msg = format!("Send message error: {}", e.to_string()).to_string(); + add_chat_message(ctx.clone(), msg); + } } } )); @@ -873,7 +880,9 @@ fn run_recv_loop(ctx: Arc) { thread::spawn(move || { loop { if let Err(e) = recv_tick(ctx.clone()) { - let _ = print_message(ctx.clone(), format!("Print messages error: {}", e.to_string()).to_string()); + if ctx.config(|o| o.debug_logs) { + let _ = print_message(ctx.clone(), format!("Print messages error: {}", e.to_string()).to_string()); + } thread::sleep(Duration::from_secs(1)); } } diff --git a/src/chat/mod.rs b/src/chat/mod.rs index 3a2cd58..4a50bff 100644 --- a/src/chat/mod.rs +++ b/src/chat/mod.rs @@ -215,7 +215,9 @@ pub fn recv_tick(ctx: Arc) -> Result<(), Box> { } }, Err(e) => { - println!("Read messages error: {}", e.to_string()) + if ctx.config(|o| o.debug_logs) { + add_chat_message(ctx.clone(), format!("Read messages error: {}", e.to_string())); + } } _ => {} } @@ -295,4 +297,4 @@ pub fn find_username_color(message: &str) -> Option<(String, String, String)> { } } None -} \ No newline at end of file +} diff --git a/src/chat/styles/dark.css b/src/chat/styles/dark.css index 9dca5ee..2cea07d 100644 --- a/src/chat/styles/dark.css +++ b/src/chat/styles/dark.css @@ -1,3 +1,3 @@ .message-content { color:rgb(255, 255, 255); } .message-date { color:rgb(146, 146, 146); } -.message-ip { color:rgb(73, 73, 73); } \ No newline at end of file +.message-ip { color:rgb(73, 73, 73); }