use super::AppModel;
#[cfg(test)]
use crate::binding::Workspace;
use crate::git_tree::GitTree;
use std::path::Path;
impl AppModel {
pub fn take(&mut self) -> bool {
let latest = crate::state::latest_snapshot(&self.cell);
let landed = !std::sync::Arc::ptr_eq(&self.snap, &latest);
if landed {
self.snap = latest;
if let Some(bytes) = self.snap.ui_bytes.clone()
&& !self.ui.is_echo(&bytes)
{
self.ui.adopt(&bytes);
}
}
landed
}
pub fn snapshot_cell(&self) -> crate::state::SnapshotCell {
std::sync::Arc::clone(&self.cell)
}
pub fn ui_json_path(&self) -> std::path::PathBuf {
self.roots.ui_json()
}
pub fn now_unix(&self) -> i64 {
self.clock.unix()
}
pub fn cadence(&self) -> super::Cadence {
self.snap.cadence
}
#[cfg(test)]
pub(crate) fn workspaces(&self) -> &[Workspace] {
&self.snap.workspaces
}
#[cfg(test)]
pub(crate) fn ws_listing(&self) -> crate::boundary::reply::Workspaces {
crate::boundary::answer::workspaces(&self.snap, &self.ui, self.now_unix())
}
#[cfg(test)]
pub(crate) fn dirty_handle(&self) -> crate::state::DirtySet {
self.dirty.clone()
}
pub fn tree(&self, ws: &Path) -> Option<&GitTree> {
self.snap.trees.get(ws)
}
pub fn workspace_path(&self, name: &str) -> Option<std::path::PathBuf> {
self.snap.ws_path(name).ok()
}
pub fn workspace_stats(&self, ws: &Path) -> (usize, usize, bool) {
crate::boundary::answer::workspace_stats(&self.snap, &self.ui, ws)
}
pub fn answer(
&self,
deps: &crate::boundary::dispatch::Deps,
query: &crate::boundary::Query,
now_unix: i64,
) -> Result<crate::boundary::reply::Reply, String> {
crate::boundary::answer::answer(query, deps, &self.ui, now_unix)
}
}