- Added `chat.rs` for rendering chat messages with timestamps and roles. - Introduced `markdown.rs` for rendering markdown content with styling. - Created `status.rs` to display the application status bar with session and message counts. - Developed `workflow.rs` to show the current workflow status, including tool calls and active jobs. - Established a `theme.rs` for centralized color management across the UI. - Updated `mod.rs` to include new modules and manage rendering logic.
44 lines
1002 B
Rust
44 lines
1002 B
Rust
use std::path::{Path, PathBuf};
|
|
use std::fs;
|
|
|
|
pub struct SessionLock {
|
|
path: PathBuf,
|
|
pid: u32,
|
|
}
|
|
|
|
impl SessionLock {
|
|
pub fn new(session_dir: &Path) -> Self {
|
|
SessionLock {
|
|
path: session_dir.join(".lock"),
|
|
pid: std::process::id(),
|
|
}
|
|
}
|
|
|
|
pub fn try_lock(&self) -> std::io::Result<bool> {
|
|
if self.path.exists() {
|
|
let content = fs::read_to_string(&self.path).unwrap_or_default();
|
|
if let Ok(pid) = content.trim().parse::<u32>() {
|
|
if self.is_alive(pid) {
|
|
return Ok(false);
|
|
}
|
|
}
|
|
}
|
|
fs::write(&self.path, self.pid.to_string())?;
|
|
Ok(true)
|
|
}
|
|
|
|
pub fn unlock(&self) {
|
|
let _ = fs::remove_file(&self.path);
|
|
}
|
|
|
|
fn is_alive(&self, pid: u32) -> bool {
|
|
unsafe { libc::kill(pid as i32, 0) == 0 }
|
|
}
|
|
}
|
|
|
|
impl Drop for SessionLock {
|
|
fn drop(&mut self) {
|
|
let _ = fs::remove_file(&self.path);
|
|
}
|
|
}
|