From 5f365b259bcd71c7002090b9e7aa8b4192c7d637 Mon Sep 17 00:00:00 2001 From: bjoern Date: Wed, 21 Jul 2021 23:02:09 +0200 Subject: [PATCH] tweak connectivity html (#2549) * escape strings added to html * use more common emojis for connectivity report all emojis are from 2010 and older now. an alternative would have been to use css, however, that may have other issues and as the whole report is subject to change anyway, i go for the easy solution. * use 'modern' meta pattern, remove unused div and styles * use css instead emojis; looks better that way also, we have the same look on all systems. * add connectivity command to repl tool --- examples/repl/cmdline.rs | 9 ++++ examples/repl/main.rs | 3 +- src/scheduler/connectivity.rs | 92 ++++++++++++++++++++++++++--------- 3 files changed, 81 insertions(+), 23 deletions(-) diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 8da9460cc..3beb15a9c 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -351,6 +351,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu configure\n\ connect\n\ disconnect\n\ + connectivity\n\ maybenetwork\n\ housekeeping\n\ help imex (Import/Export)\n\ @@ -511,6 +512,14 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu "info" => { println!("{:#?}", context.get_info().await); } + "connectivity" => { + let file = dirs::home_dir() + .unwrap_or_default() + .join("connectivity.html"); + let html = context.get_connectivity_html().await; + fs::write(&file, html)?; + println!("Report written to: {:#?}", file); + } "maybenetwork" => { context.maybe_network().await; } diff --git a/examples/repl/main.rs b/examples/repl/main.rs index 68fb54947..59bda2e84 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -154,7 +154,7 @@ const IMEX_COMMANDS: [&str; 12] = [ "stop", ]; -const DB_COMMANDS: [&str; 9] = [ +const DB_COMMANDS: [&str; 10] = [ "info", "set", "get", @@ -162,6 +162,7 @@ const DB_COMMANDS: [&str; 9] = [ "configure", "connect", "disconnect", + "connectivity", "maybenetwork", "housekeeping", ]; diff --git a/src/scheduler/connectivity.rs b/src/scheduler/connectivity.rs index 25eff175b..701906a39 100644 --- a/src/scheduler/connectivity.rs +++ b/src/scheduler/connectivity.rs @@ -55,35 +55,47 @@ impl DetailedConnectivity { } } + fn to_icon(&self) -> String { + match self { + DetailedConnectivity::Error(_) + | DetailedConnectivity::Uninitialized + | DetailedConnectivity::NotConfigured => "".to_string(), + DetailedConnectivity::Connecting => "".to_string(), + DetailedConnectivity::Working + | DetailedConnectivity::InterruptingIdle + | DetailedConnectivity::Connected => "".to_string(), + } + } + fn to_string_imap(&self, _context: &Context) -> String { match self { - DetailedConnectivity::Error(e) => format!("🔴 Error: {}", e), - DetailedConnectivity::Uninitialized => "🔴 Not started".to_string(), - DetailedConnectivity::Connecting => "🟡 Connecting…".to_string(), - DetailedConnectivity::Working => "⬇️ Getting new messages…".to_string(), + DetailedConnectivity::Error(e) => format!("Error: {}", e), + DetailedConnectivity::Uninitialized => "Not started".to_string(), + DetailedConnectivity::Connecting => "Connecting…".to_string(), + DetailedConnectivity::Working => "Getting new messages…".to_string(), DetailedConnectivity::InterruptingIdle | DetailedConnectivity::Connected => { - "🟢 Connected".to_string() + "Connected".to_string() } - DetailedConnectivity::NotConfigured => "🔴 Not configured".to_string(), + DetailedConnectivity::NotConfigured => "Not configured".to_string(), } } fn to_string_smtp(&self, _context: &Context) -> String { match self { - DetailedConnectivity::Error(e) => format!("🔴 Error: {}", e), + DetailedConnectivity::Error(e) => format!("Error: {}", e), DetailedConnectivity::Uninitialized => { "(You did not try to send a message recently)".to_string() } - DetailedConnectivity::Connecting => "🟡 Connecting…".to_string(), - DetailedConnectivity::Working => "⬆️ Sending…".to_string(), + DetailedConnectivity::Connecting => "Connecting…".to_string(), + DetailedConnectivity::Working => "Sending…".to_string(), // We don't know any more than that the last message was sent successfully; // since sending the last message, connectivity could have changed, which we don't notice // until another message is sent DetailedConnectivity::InterruptingIdle | DetailedConnectivity::Connected => { - "🟢 Your last message was sent successfully".to_string() + "Your last message was sent successfully".to_string() } - DetailedConnectivity::NotConfigured => "🔴 Not configured".to_string(), + DetailedConnectivity::NotConfigured => "Not configured".to_string(), } } @@ -244,8 +256,36 @@ impl Context { /// This comes as an HTML from the core so that we can easily improve it /// and the improvement instantly reaches all UIs. pub async fn get_connectivity_html(&self) -> String { - let mut ret = - "\n\n".to_string(); + let mut ret = r#" + + + + + + + "# + .to_string(); let lock = self.scheduler.read().await; let (folders_states, smtp) = match &*lock { @@ -282,7 +322,7 @@ impl Context { }; drop(lock); - ret += "

Incoming messages:

"; + ret += ""; - ret += "

Outgoing messages: