Skip to content

Commit

Permalink
Implement Default for ApiAvailibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Sep 26, 2024
1 parent f09bb43 commit 1ca7298
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
22 changes: 14 additions & 8 deletions mullvad-api/src/availability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ pub enum Error {
Interrupted(#[from] broadcast::error::RecvError),
}

#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct State {
suspended: bool,
pause_background: bool,
offline: bool,
inactive: bool,
}

#[derive(Clone, Debug)]
pub struct ApiAvailability(Arc<Mutex<ApiAvailabilityState>>);

Expand All @@ -34,6 +26,14 @@ struct ApiAvailabilityState {
inactivity_timer: Option<tokio::task::JoinHandle<()>>,
}

#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct State {
suspended: bool,
pause_background: bool,
offline: bool,
inactive: bool,
}

impl State {
pub const fn is_suspended(&self) -> bool {
self.suspended
Expand Down Expand Up @@ -179,6 +179,12 @@ impl ApiAvailability {
}
}

impl Default for ApiAvailability {
fn default() -> Self {
ApiAvailability::new(State::default())
}
}

impl ApiAvailabilityState {
fn suspend(&mut self) {
if !self.state.suspended {
Expand Down
8 changes: 5 additions & 3 deletions mullvad-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl Runtime {
Runtime {
handle,
address_cache: AddressCache::with_static_addr(address),
api_availability: ApiAvailability::new(availability::State::default()),
api_availability: ApiAvailability::default(),
}
}

Expand All @@ -351,7 +351,7 @@ impl Runtime {
Ok(Runtime {
handle,
address_cache: AddressCache::new(None)?,
api_availability: ApiAvailability::new(availability::State::default()),
api_availability: ApiAvailability::default(),
#[cfg(target_os = "android")]
socket_bypass_tx,
})
Expand Down Expand Up @@ -396,10 +396,12 @@ impl Runtime {
}
};

let api_availability = ApiAvailability::default();

Ok(Runtime {
handle,
address_cache,
api_availability: ApiAvailability::new(availability::State::default()),
api_availability,
#[cfg(target_os = "android")]
socket_bypass_tx,
})
Expand Down

0 comments on commit 1ca7298

Please sign in to comment.