Add logging level to Generic jobs

Not every job success should be shown to the user, for example updating
the sqlite3 database. So introduce a level to only show relevant
notifications.
memfd
Manos Pitsidianakis 2020-08-26 19:15:31 +03:00
parent c6f11fb592
commit 843616221e
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 21 additions and 9 deletions

View File

@ -287,6 +287,7 @@ pub trait MailListingTrait: ListingTrait {
handle, handle,
channel, channel,
on_finish: None, on_finish: None,
logging_level: melib::LoggingLevel::DEBUG,
}, },
); );
} }
@ -325,6 +326,7 @@ pub trait MailListingTrait: ListingTrait {
handle, handle,
channel, channel,
on_finish: None, on_finish: None,
logging_level: melib::LoggingLevel::DEBUG,
}, },
); );
} }

View File

@ -1194,6 +1194,7 @@ impl Component for MailView {
} }
} }
}))), }))),
logging_level: melib::LoggingLevel::DEBUG,
}, },
); );
return true; return true;

View File

@ -174,6 +174,7 @@ pub enum JobRequest {
), ),
Generic { Generic {
name: Cow<'static, str>, name: Cow<'static, str>,
logging_level: melib::LoggingLevel,
handle: JoinHandle, handle: JoinHandle,
channel: JobChannel<()>, channel: JobChannel<()>,
on_finish: Option<crate::types::CallbackFn>, on_finish: Option<crate::types::CallbackFn>,
@ -645,6 +646,7 @@ impl Account {
.into(), .into(),
handle, handle,
channel, channel,
logging_level: melib::LoggingLevel::TRACE,
on_finish: None, on_finish: None,
}, },
); );
@ -693,6 +695,7 @@ impl Account {
.into(), .into(),
handle, handle,
channel, channel,
logging_level: melib::LoggingLevel::TRACE,
on_finish: None, on_finish: None,
}, },
); );
@ -752,6 +755,7 @@ impl Account {
.into(), .into(),
handle, handle,
channel, channel,
logging_level: melib::LoggingLevel::TRACE,
on_finish: None, on_finish: None,
}, },
); );
@ -796,6 +800,7 @@ impl Account {
.into(), .into(),
handle, handle,
channel, channel,
logging_level: melib::LoggingLevel::TRACE,
on_finish: None, on_finish: None,
}, },
); );
@ -1950,6 +1955,7 @@ impl Account {
ref mut channel, ref mut channel,
handle: _, handle: _,
ref mut on_finish, ref mut on_finish,
logging_level,
} => { } => {
let r = channel.try_recv().unwrap(); let r = channel.try_recv().unwrap();
match r { match r {
@ -1962,16 +1968,18 @@ impl Account {
))) )))
.expect("Could not send event on main channel"); .expect("Could not send event on main channel");
} }
Some(Ok(_)) => { Some(Ok(())) if on_finish.is_none() => {
self.sender if logging_level <= melib::LoggingLevel::INFO {
.send(ThreadEvent::UIEvent(UIEvent::Notification( self.sender
Some(format!("{}: {} succeeded", &self.name, name,)), .send(ThreadEvent::UIEvent(UIEvent::Notification(
String::new(), Some(format!("{}: {} succeeded", &self.name, name,)),
Some(crate::types::NotificationType::INFO), String::new(),
))) Some(crate::types::NotificationType::INFO),
.expect("Could not send event on main channel"); )))
.expect("Could not send event on main channel");
}
} }
None => {} Some(Ok(())) | None => {}
} }
if on_finish.is_some() { if on_finish.is_some() {
self.sender self.sender

View File

@ -882,6 +882,7 @@ impl State {
handle, handle,
channel, channel,
on_finish: None, on_finish: None,
logging_level: melib::LoggingLevel::INFO,
}, },
); );
self.context.replies.push_back(UIEvent::Notification( self.context.replies.push_back(UIEvent::Notification(