feat(server): refactor handlers, router, state management, and memory tools

This commit is contained in:
Riz Ashraf committed 2026-10-02 07:27:37 +01:00
1 parent 87ddb01063
commit a083719cf1
36 files changed
+1899 -597

No files matched your search

+25 -25
View File
@@ -1,8 +1,8 @@
use crate::state::MemoryState;
use crate::models::StickyNote;
use std::sync::Arc;
use tokio::time::{sleep, Duration};
use crate::state::MemoryState;
use arboard::Clipboard;
use std::sync::Arc;
use tokio::time::{Duration, sleep};
pub fn spawn_watcher(state: Arc<MemoryState>) {
tokio::spawn(async move {
let mut last_text = String::new();
@@ -18,28 +18,28 @@ pub fn spawn_watcher(state: Arc<MemoryState>) {
continue;
}
if let Ok(mut clipboard) = Clipboard::new() {
if let Ok(text) = clipboard.get_text() {
if text != last_text && !text.trim().is_empty() {
last_text = text.clone();
let note = StickyNote {
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs(),
content: text,
expires_at: None,
};
state.code.sticky.modify(|notes| {
notes.push(note.clone());
});
// We use rebuild_index to index the new sticky note
state.rebuild_index().await;
}
}
if let Ok(mut clipboard) = Clipboard::new()
&& let Ok(text) = clipboard.get_text()
&& text != last_text
&& !text.trim().is_empty()
{
last_text = text.clone();
let note = StickyNote {
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs(),
content: text,
expires_at: None,
};
state.code.sticky.modify(|notes| {
notes.push(note.clone());
});
// We use rebuild_index to index the new sticky note
state.rebuild_index().await;
}
}
});