F5 thalamus: cached channel status, refresh on entry
Channel status is cached on App and refreshed when switching to F5, not polled every render frame. Shows connected/disconnected status and unread count per channel daemon. Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
48b8ba73d8
commit
36afa90cdb
3 changed files with 89 additions and 22 deletions
|
|
@ -368,6 +368,16 @@ pub struct App {
|
|||
pub(crate) agent_log_view: bool,
|
||||
/// Agent state from last cycle update.
|
||||
pub(crate) agent_state: Vec<crate::subconscious::subconscious::AgentSnapshot>,
|
||||
/// Cached channel info for F5 screen (refreshed on status tick).
|
||||
pub(crate) channel_status: Vec<ChannelStatus>,
|
||||
}
|
||||
|
||||
/// Channel info for display on F5 screen.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct ChannelStatus {
|
||||
pub name: String,
|
||||
pub connected: bool,
|
||||
pub unread: u32,
|
||||
}
|
||||
|
||||
/// Screens toggled by F-keys.
|
||||
|
|
@ -439,6 +449,7 @@ impl App {
|
|||
agent_selected: 0,
|
||||
agent_log_view: false,
|
||||
agent_state: Vec::new(),
|
||||
channel_status: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -826,9 +837,62 @@ impl App {
|
|||
self.draw_main(frame, size);
|
||||
}
|
||||
|
||||
/// Refresh channel status by querying daemon sockets.
|
||||
/// Called from the status tick, not every render frame.
|
||||
pub fn refresh_channels(&mut self) {
|
||||
let channels_dir = dirs::home_dir()
|
||||
.unwrap_or_default()
|
||||
.join(".consciousness/channels");
|
||||
|
||||
let mut status = Vec::new();
|
||||
|
||||
// Read supervisor config to know which daemons exist
|
||||
let mut sup = crate::thalamus::supervisor::Supervisor::new();
|
||||
sup.load_config();
|
||||
|
||||
for (daemon_name, enabled, alive) in sup.status() {
|
||||
if !alive {
|
||||
status.push(ChannelStatus {
|
||||
name: daemon_name,
|
||||
connected: false,
|
||||
unread: 0,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to connect and call list()
|
||||
let sock = channels_dir.join(format!("{}.sock", daemon_name));
|
||||
match std::os::unix::net::UnixStream::connect(&sock) {
|
||||
Ok(_stream) => {
|
||||
// For now, just show the daemon as connected
|
||||
// TODO: actual capnp list() call
|
||||
status.push(ChannelStatus {
|
||||
name: daemon_name,
|
||||
connected: true,
|
||||
unread: 0,
|
||||
});
|
||||
}
|
||||
Err(_) => {
|
||||
status.push(ChannelStatus {
|
||||
name: daemon_name,
|
||||
connected: false,
|
||||
unread: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.channel_status = status;
|
||||
}
|
||||
|
||||
pub(crate) fn set_screen(&mut self, screen: Screen) {
|
||||
self.screen = screen;
|
||||
self.debug_scroll = 0;
|
||||
// Refresh data for status screens on entry
|
||||
match screen {
|
||||
Screen::Thalamus => self.refresh_channels(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue