refactoring, more config, packaging

This commit is contained in:
John Smith
2022-05-16 11:52:48 -04:00
parent 444f65d76d
commit ef1f5d7b52
42 changed files with 1329 additions and 368 deletions

View File

@@ -88,14 +88,29 @@ impl ClientApiConnection {
}
async fn process_veilid_state<'a>(
&'a mut self,
state: veilid_state::Reader<'a>,
veilid_state: veilid_state::Reader<'a>,
) -> Result<(), String> {
let mut inner = self.inner.borrow_mut();
// Process attachment state
let attachment = state.reborrow().get_attachment().map_err(map_to_string)?;
let state = attachment.get_state().map_err(map_to_string)?;
inner.comproc.update_attachment(state);
let attachment = veilid_state
.reborrow()
.get_attachment()
.map_err(map_to_string)?;
let attachment_state = attachment.get_state().map_err(map_to_string)?;
let network = veilid_state
.reborrow()
.get_network()
.map_err(map_to_string)?;
let started = network.get_started();
let bps_down = network.get_bps_down();
let bps_up = network.get_bps_up();
inner.comproc.update_attachment(attachment_state);
inner
.comproc
.update_network_status(started, bps_down, bps_up);
Ok(())
}

View File

@@ -277,6 +277,12 @@ debug - send a debugging command to the Veilid server
self.inner_mut().ui.set_attachment_state(state);
}
pub fn update_network_status(&mut self, started: bool, bps_down: u64, bps_up: u64) {
self.inner_mut()
.ui
.set_network_status(started, bps_down, bps_up);
}
pub fn add_log_message(&mut self, message: &str) {
self.inner().ui.add_node_event(message);
}

View File

@@ -49,6 +49,8 @@ pub type UICallback = Box<dyn Fn(&mut Cursive) + Send>;
struct UIState {
attachment_state: Dirty<AttachmentState>,
network_started: Dirty<bool>,
network_down_up: Dirty<(f32, f32)>,
connection_state: Dirty<ConnectionState>,
}
@@ -56,6 +58,8 @@ impl UIState {
pub fn new() -> Self {
Self {
attachment_state: Dirty::new(AttachmentState::Detached),
network_started: Dirty::new(false),
network_down_up: Dirty::new((0.0, 0.0)),
connection_state: Dirty::new(ConnectionState::Disconnected),
}
}
@@ -221,6 +225,15 @@ impl UI {
AttachmentState::Detaching => "Detaching [////]",
}
}
fn render_network_status(inner: &mut UIInner) -> String {
match inner.ui_state.network_started.get() {
false => "Down: ----KB/s Up: ----KB/s".to_owned(),
true => {
let (d, u) = inner.ui_state.network_down_up.get();
format!("Down: {:.2}KB/s Up: {:.2}KB/s", d, u)
}
}
}
fn render_button_attach<'a>(inner: &mut UIInner) -> (&'a str, bool) {
if let ConnectionState::Connected(_, _) = inner.ui_state.connection_state.get() {
match inner.ui_state.attachment_state.get() {
@@ -576,7 +589,7 @@ impl UI {
status.append_styled("|", ColorStyle::highlight_inactive());
// Add bandwidth status
status.append_styled(
" Down: 0.0KB/s Up: 0.0KB/s ",
format!(" {} ", UI::render_network_status(&mut inner)),
ColorStyle::highlight_inactive(),
);
status.append_styled("|", ColorStyle::highlight_inactive());
@@ -599,6 +612,12 @@ impl UI {
refresh_statusbar = true;
refresh_button_attach = true;
}
if inner.ui_state.network_started.take_dirty() {
refresh_statusbar = true;
}
if inner.ui_state.network_down_up.take_dirty() {
refresh_statusbar = true;
}
if inner.ui_state.connection_state.take_dirty() {
refresh_statusbar = true;
refresh_button_attach = true;
@@ -757,6 +776,15 @@ impl UI {
inner.ui_state.attachment_state.set(state);
let _ = inner.cb_sink.send(Box::new(UI::update_cb));
}
pub fn set_network_status(&mut self, started: bool, bps_down: u64, bps_up: u64) {
let mut inner = self.inner.borrow_mut();
inner.ui_state.network_started.set(started);
inner.ui_state.network_down_up.set((
((bps_down as f64) / 1000.0f64) as f32,
((bps_up as f64) / 1000.0f64) as f32,
));
let _ = inner.cb_sink.send(Box::new(UI::update_cb));
}
pub fn set_connection_state(&mut self, state: ConnectionState) {
let mut inner = self.inner.borrow_mut();
inner.ui_state.connection_state.set(state);