dave: refactor a bit

pulling tokens isn't really a part of rendering,
so let's pull that out

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-04-16 22:41:41 -07:00
parent bf18eb4e69
commit b50bc2e988

View File

@@ -97,9 +97,14 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
}
}
fn render(&mut self, app_ctx: &AppContext, ui: &mut egui::Ui) {
/// Process incoming tokens from the ai backend
fn process_events(&mut self, app_ctx: &AppContext) -> bool {
let mut should_send = false;
if let Some(recvr) = &self.incoming_tokens {
let Some(recvr) = &self.incoming_tokens else {
return should_send;
};
while let Ok(res) = recvr.try_recv() {
if let Some(avatar) = &mut self.avatar {
avatar.random_nudge();
@@ -133,8 +138,11 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
}
}
}
should_send
}
fn render(&mut self, app_ctx: &AppContext, ui: &mut egui::Ui) {
// Scroll area for chat messages
egui::Frame::new()
.inner_margin(egui::Margin {
@@ -150,26 +158,11 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
.show(ui, |ui| {
ui.vertical(|ui| {
self.render_chat(ui);
self.inputbox(app_ctx, ui);
})
});
self.inputbox(app_ctx, ui);
});
/*
// he lives in the sidebar now
if let Some(avatar) = &mut self.avatar {
let avatar_size = Vec2::splat(300.0);
let pos = Vec2::splat(100.0).to_pos2();
let pos = Rect::from_min_max(pos, pos + avatar_size);
avatar.render(pos, ui);
}
*/
// send again
if should_send {
self.send_user_message(app_ctx, ui.ctx());
}
}
fn render_chat(&self, ui: &mut egui::Ui) {
@@ -388,6 +381,10 @@ impl notedeck::App for Dave {
*/
//update_dave(self, ctx, ui.ctx());
let should_send = self.process_events(ctx);
self.render(ctx, ui);
if should_send {
self.send_user_message(ctx, ui.ctx());
}
}
}