pub struct ConnectivityReporter {
status: Arc<RwLock<ConnectivityStatus>>,
first_failure_at: Arc<RwLock<Option<Instant>>>,
app_handle: Option<AppHandle>,
}Expand description
Shared reachability state and transition logic.
This is the single place that mutates reachability and emits events. It is
cheap to clone (all fields are Arc/Option) and is shared by:
- the
ConnectivityMonitor(commands, offline recovery probe), and OnlineRepository, which reports the outcome of every server request.
Reachability is therefore driven by real traffic; the probe only fills the gap while offline.
Fields§
§status: Arc<RwLock<ConnectivityStatus>>§first_failure_at: Arc<RwLock<Option<Instant>>>Timestamp of the first network failure in the current failure streak.
Used to debounce the transition to offline (see OFFLINE_CONFIRM_WINDOW).
app_handle: Option<AppHandle>Implementations§
Source§impl ConnectivityReporter
impl ConnectivityReporter
fn new( status: Arc<RwLock<ConnectivityStatus>>, app_handle: Option<AppHandle>, ) -> Self
Sourcepub async fn is_reachable(&self) -> bool
pub async fn is_reachable(&self) -> bool
Current reachability as seen by this reporter (shared with the monitor and the UI). Useful for callers that want to branch on connectivity.
Sourcepub async fn report_success(&self)
pub async fn report_success(&self)
Report that a real server request succeeded (or that the server answered at all, e.g. with 401/404/5xx). The server is up — recover instantly.
Sourcepub async fn report_network_failure(&self, error: Option<String>)
pub async fn report_network_failure(&self, error: Option<String>)
Report that a real server request failed with a network-level error
(connection refused, timeout, DNS). Subject to the time-window debounce:
we only flip to offline once failures have persisted for
OFFLINE_CONFIRM_WINDOW with no intervening success.
Sourceasync fn apply_probe_result(&self, is_reachable: bool, error: Option<String>)
async fn apply_probe_result(&self, is_reachable: bool, error: Option<String>)
Apply a deliberate reachability probe result (offline recovery probe or a
manual check). Unlike report_network_failure, a probe is an explicit
reachability test, so its result is applied immediately without debounce.
Sourceasync fn set_reachable(&self, is_reachable: bool, error: Option<String>)
async fn set_reachable(&self, is_reachable: bool, error: Option<String>)
Core transition: update status and emit events only on an actual change.
Sourceasync fn emit_connectivity_change(&self, is_reachable: bool)
async fn emit_connectivity_change(&self, is_reachable: bool)
Emit connectivity change event to frontend
Sourceasync fn emit_server_reconnected(&self)
async fn emit_server_reconnected(&self)
Emit server reconnected event to frontend
Trait Implementations§
Source§impl Clone for ConnectivityReporter
impl Clone for ConnectivityReporter
Source§fn clone(&self) -> ConnectivityReporter
fn clone(&self) -> ConnectivityReporter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more