mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
feat: log actual connectivity changes as ConnectivityChanged payload
This commit is contained in:
@@ -7,6 +7,7 @@ use crate::chat::ChatId;
|
|||||||
use crate::contact::ContactId;
|
use crate::contact::ContactId;
|
||||||
use crate::ephemeral::Timer as EphemeralTimer;
|
use crate::ephemeral::Timer as EphemeralTimer;
|
||||||
use crate::message::MsgId;
|
use crate::message::MsgId;
|
||||||
|
use crate::scheduler::connectivity::DetailedConnectivity;
|
||||||
use crate::webxdc::StatusUpdateSerial;
|
use crate::webxdc::StatusUpdateSerial;
|
||||||
|
|
||||||
/// Event payload.
|
/// Event payload.
|
||||||
@@ -258,7 +259,9 @@ pub enum EventType {
|
|||||||
/// This means that you should refresh the connectivity view
|
/// This means that you should refresh the connectivity view
|
||||||
/// and possibly the connectivtiy HTML; see dc_get_connectivity() and
|
/// and possibly the connectivtiy HTML; see dc_get_connectivity() and
|
||||||
/// dc_get_connectivity_html() for details.
|
/// dc_get_connectivity_html() for details.
|
||||||
ConnectivityChanged,
|
ConnectivityChanged {
|
||||||
|
connectivity: Option<DetailedConnectivity>,
|
||||||
|
},
|
||||||
|
|
||||||
/// The user's avatar changed.
|
/// The user's avatar changed.
|
||||||
SelfavatarChanged,
|
SelfavatarChanged,
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ impl Context {
|
|||||||
modified: time(),
|
modified: time(),
|
||||||
});
|
});
|
||||||
|
|
||||||
self.emit_event(EventType::ConnectivityChanged);
|
self.emit_event(EventType::ConnectivityChanged { connectivity: None });
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::{iter::once, ops::Deref, sync::Arc};
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use humansize::{format_size, BINARY};
|
use humansize::{format_size, BINARY};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::events::EventType;
|
use crate::events::EventType;
|
||||||
@@ -14,7 +15,9 @@ use crate::{stock_str, tools};
|
|||||||
|
|
||||||
use super::InnerSchedulerState;
|
use super::InnerSchedulerState;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumProperty, PartialOrd, Ord)]
|
#[derive(
|
||||||
|
Debug, Clone, Copy, PartialEq, Eq, EnumProperty, PartialOrd, Ord, Serialize, Deserialize,
|
||||||
|
)]
|
||||||
pub enum Connectivity {
|
pub enum Connectivity {
|
||||||
NotConnected = 1000,
|
NotConnected = 1000,
|
||||||
Connecting = 2000,
|
Connecting = 2000,
|
||||||
@@ -27,8 +30,10 @@ pub enum Connectivity {
|
|||||||
// the top) take priority. This means that e.g. if any folder has an error - usually
|
// the top) take priority. This means that e.g. if any folder has an error - usually
|
||||||
// because there is no internet connection - the connectivity for the whole
|
// because there is no internet connection - the connectivity for the whole
|
||||||
// account will be `Notconnected`.
|
// account will be `Notconnected`.
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Eq, EnumProperty, PartialOrd)]
|
#[derive(
|
||||||
enum DetailedConnectivity {
|
Debug, Default, Clone, PartialEq, Eq, EnumProperty, PartialOrd, Serialize, Deserialize,
|
||||||
|
)]
|
||||||
|
pub enum DetailedConnectivity {
|
||||||
Error(String),
|
Error(String),
|
||||||
#[default]
|
#[default]
|
||||||
Uninitialized,
|
Uninitialized,
|
||||||
@@ -57,7 +62,7 @@ impl DetailedConnectivity {
|
|||||||
DetailedConnectivity::Uninitialized => Some(Connectivity::NotConnected),
|
DetailedConnectivity::Uninitialized => Some(Connectivity::NotConnected),
|
||||||
DetailedConnectivity::Connecting => Some(Connectivity::Connecting),
|
DetailedConnectivity::Connecting => Some(Connectivity::Connecting),
|
||||||
DetailedConnectivity::Working => Some(Connectivity::Working),
|
DetailedConnectivity::Working => Some(Connectivity::Working),
|
||||||
DetailedConnectivity::InterruptingIdle => Some(Connectivity::Connected),
|
DetailedConnectivity::InterruptingIdle => Some(Connectivity::Connecting),
|
||||||
DetailedConnectivity::Connected => Some(Connectivity::Connected),
|
DetailedConnectivity::Connected => Some(Connectivity::Connected),
|
||||||
|
|
||||||
// Just don't return a connectivity, probably the folder is configured not to be
|
// Just don't return a connectivity, probably the folder is configured not to be
|
||||||
@@ -131,11 +136,13 @@ impl DetailedConnectivity {
|
|||||||
pub(crate) struct ConnectivityStore(Arc<Mutex<DetailedConnectivity>>);
|
pub(crate) struct ConnectivityStore(Arc<Mutex<DetailedConnectivity>>);
|
||||||
|
|
||||||
impl ConnectivityStore {
|
impl ConnectivityStore {
|
||||||
async fn set(&self, context: &Context, v: DetailedConnectivity) {
|
async fn set(&self, context: &Context, detailed_connectivity: DetailedConnectivity) {
|
||||||
{
|
{
|
||||||
*self.0.lock().await = v;
|
*self.0.lock().await = detailed_connectivity.clone();
|
||||||
}
|
}
|
||||||
context.emit_event(EventType::ConnectivityChanged);
|
context.emit_event(EventType::ConnectivityChanged {
|
||||||
|
connectivity: Some(detailed_connectivity),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn set_err(&self, context: &Context, e: impl ToString) {
|
pub(crate) async fn set_err(&self, context: &Context, e: impl ToString) {
|
||||||
@@ -215,7 +222,7 @@ pub(crate) async fn maybe_network_lost(context: &Context, stores: Vec<Connectivi
|
|||||||
}
|
}
|
||||||
drop(connectivity_lock);
|
drop(connectivity_lock);
|
||||||
}
|
}
|
||||||
context.emit_event(EventType::ConnectivityChanged);
|
context.emit_event(EventType::ConnectivityChanged { connectivity: None });
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ConnectivityStore {
|
impl fmt::Debug for ConnectivityStore {
|
||||||
|
|||||||
Reference in New Issue
Block a user