diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 309eb6ab4..b429028a3 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -275,7 +275,15 @@ pub unsafe extern "C" fn dc_get_connectivity_html( return "".strdup(); } let ctx = &*context; - block_on(async move { ctx.get_connectivity_html().await.strdup() }) + block_on(async move { + match ctx.get_connectivity_html().await { + Ok(html) => html.strdup(), + Err(err) => { + error!(ctx, "Failed to get connectivity html: {}", err); + "".strdup() + } + } + }) } #[no_mangle] diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 3b0e797d2..12a59823b 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -514,9 +514,15 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu 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); + match context.get_connectivity_html().await { + Ok(html) => { + fs::write(&file, html)?; + println!("Report written to: {:#?}", file); + } + Err(err) => { + bail!("Failed to get connectivity html: {}", err); + } + } } "maybenetwork" => { context.maybe_network().await; diff --git a/src/scheduler/connectivity.rs b/src/scheduler/connectivity.rs index 6f9b55c12..c110486ec 100644 --- a/src/scheduler/connectivity.rs +++ b/src/scheduler/connectivity.rs @@ -8,8 +8,9 @@ use crate::events::EventType; use crate::quota::{ QUOTA_ERROR_THRESHOLD_PERCENTAGE, QUOTA_MAX_AGE_SECONDS, QUOTA_WARN_THRESHOLD_PERCENTAGE, }; -use crate::{config::Config, scheduler::Scheduler}; +use crate::{config::Config, dc_tools, scheduler::Scheduler}; use crate::{context::Context, log::LogExt}; +use anyhow::{anyhow, Result}; use humansize::{file_size_opts, FileSize}; #[derive(Debug, Clone, Copy, PartialEq, Eq, EnumProperty, PartialOrd, Ord)] @@ -297,7 +298,7 @@ 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 { + pub async fn get_connectivity_html(&self) -> Result { let mut ret = r#" @@ -308,13 +309,29 @@ impl Context { list-style-type: none; padding-left: 1em; } - .dot { height: 0.9em; width: 0.9em; + border: 1px solid #888; border-radius: 50%; display: inline-block; position: relative; left: -0.1em; top: 0.1em; } + .bar { + width: 90%; + border: 1px solid #888; + border-radius: .5em; + margin-top: .2em; + margin-bottom: 1em; + position: relative; left: -0.2em; + } + .progress { + min-width:1.8em; + height: 1em; + border-radius: .45em; + color: white; + text-align: center; + padding-bottom: 2px; + } .red { background-color: #f33b2d; } @@ -358,8 +375,7 @@ impl Context { smtp.state.connectivity.clone(), ), Scheduler::Stopped => { - ret += "Not started\n"; - return ret; + return Err(anyhow!("Not started")); } }; drop(lock); @@ -408,7 +424,14 @@ impl Context { ret += &*escaper::encode_minimal(&detailed.to_string_smtp(self)); ret += ""; - ret += "

Quota