Something went wrong. Try again.
[AWIP] Local-first peer-to-peer connectivity and sharing across Android, Linux and Windows, made with Tauri
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748use std::sync::RwLock;
use super::{InvalidTransition, LifecycleState};
pub struct AppState { lifecycle: RwLock<LifecycleState>,}
impl AppState { pub fn new() -> Self { Self::default() }
pub fn lifecycle(&self) -> eros::Result<LifecycleState> { self.lifecycle .read() .map(|lifecycle| *lifecycle) .map_err(|_| { eros::error!("application lifecycle lock poisoned").context("read app state") }) }
pub fn transition(&self, next: LifecycleState) -> eros::Result<()> { let mut current = self.lifecycle.write().map_err(|_| { eros::error!("application lifecycle lock poisoned").context("write app state") })?;
if !current.can_transition(next) { return Err(eros::error!(InvalidTransition { from: *current, to: next, }) .context("advance application lifecycle")); }
*current = next; Ok(()) }}
impl Default for AppState { fn default() -> Self { Self { lifecycle: RwLock::new(LifecycleState::Created), } }}