Debug logging, second try

This commit is contained in:
Hocuri
2022-05-05 11:56:03 +02:00
committed by Septias
parent fc386f4fa1
commit b5d6f44b13
2 changed files with 41 additions and 0 deletions

View File

@@ -2,16 +2,21 @@
use anyhow::{ensure, Context as _, Result};
use strum::{EnumProperty as EnumPropertyTrait, IntoEnumIterator};
use async_std::fs::File;
use async_std::io::WriteExt;
use strum_macros::{AsRefStr, Display, EnumIter, EnumProperty, EnumString};
use crate::blob::BlobObject;
use crate::chat::ChatId;
use crate::constants::DC_VERSION_STR;
use crate::contact::addr_cmp;
use crate::context::Context;
use crate::events::EventType;
use crate::message::{self, Message, MsgId, Viewtype};
use crate::mimefactory::RECOMMENDED_FILE_SIZE;
use crate::provider::{get_provider_by_id, Provider};
use crate::tools::{get_abs_path, improve_single_line_input, EmailAddress};
use crate::{chat, webxdc};
/// The available configuration keys.
#[derive(
@@ -190,6 +195,9 @@ pub enum Config {
///
/// See `crate::authres::update_authservid_candidates`.
AuthservIdCandidates,
// TODO docs, deltachat.h
#[strum(props(default = "0"))]
DebugLogging,
}
impl Context {
@@ -319,6 +327,24 @@ impl Context {
.set_raw_config(key.as_ref(), value.as_deref())
.await?;
}
Config::DebugLogging => {
if value == Some("0") || value == Some("") || value == None {
if let Some(webxdc_message_id) =
self.sql.get_raw_config_int(Config::DebugLogging).await?
{
// TODO possible recursion?
message::delete_msgs(self, &[MsgId::new(webxdc_message_id)]).await?;
}
} else {
let data: &[u8] = include_bytes!("../test-data/webxdc/minimal.xdc");
let file = BlobObject::create(self, "webxdc_debug_logging.xdc", data).await?;
let mut instance = Message::new(Viewtype::Webxdc);
instance.set_file(file.to_abs_path().to_str(), None);
let instance_msg_id =
chat::add_device_msg(self, None, Some(&mut instance)).await?;
}
}
_ => {
self.sql.set_raw_config(key.as_ref(), value).await?;
}

View File

@@ -436,6 +436,21 @@ impl Context {
id: self.id,
typ: event,
});
let context = self.clone();
async_std::task::spawn(async move {
// TODO synchronously is prob. better
match context.get_config_int(Config::DebugLogging).await {
Err(e) => eprintln!("Can't get debug logging config: {:#}", e),
Ok(0) => {}
Ok(debug_logging_webxdc) => {
let time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as i64;
// TODO
}
}
});
}
/// Emits a generic MsgsChanged event (without chat or message id)