31 lines
793 B
Rust
31 lines
793 B
Rust
|
|
use std::path::PathBuf;
|
||
|
|
use std::sync::Mutex;
|
||
|
|
use tokio::sync::watch;
|
||
|
|
|
||
|
|
pub struct SessionState {
|
||
|
|
pub project_root: Mutex<Option<PathBuf>>,
|
||
|
|
pub cancel_tx: watch::Sender<bool>,
|
||
|
|
pub cancel_rx: watch::Receiver<bool>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Default for SessionState {
|
||
|
|
fn default() -> Self {
|
||
|
|
let (cancel_tx, cancel_rx) = watch::channel(false);
|
||
|
|
Self {
|
||
|
|
project_root: Mutex::new(None),
|
||
|
|
cancel_tx,
|
||
|
|
cancel_rx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl SessionState {
|
||
|
|
pub fn get_project_root(&self) -> Result<PathBuf, String> {
|
||
|
|
let root_guard = self.project_root.lock().map_err(|e| e.to_string())?;
|
||
|
|
let root = root_guard
|
||
|
|
.as_ref()
|
||
|
|
.ok_or_else(|| "No project is currently open.".to_string())?;
|
||
|
|
Ok(root.clone())
|
||
|
|
}
|
||
|
|
}
|