Skip to content

Commit

Permalink
avoid terminate a closed connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackhr-arch committed Sep 6, 2024
1 parent a453420 commit 010e8cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/bin/clashtui/tui/frontend/tabs/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ impl Drawable for ConnctionTab {
if self.selected_con.is_some() {
match ev.code {
KeyCode::Enter => {
self.backend_content = Some(Call::Connection(BackendOp::Terminal(
self.selected_con.take().unwrap().id,
)))
self.backend_content = self
.selected_con
.take()
.unwrap()
.id
.map(|id| Call::Connection(BackendOp::Terminal(id)))
}
// KeyCode::Left => todo!(),
// KeyCode::Right => todo!(),
Expand Down
21 changes: 13 additions & 8 deletions src/bin/clashtui/tui/frontend/tabs/connection/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Connection {
start: String,
upload: u64,
download: u64,
pub id: String,
pub id: Option<String>,
}
impl Connection {
pub fn build_col(&self) -> Raw::Row {
Expand All @@ -23,7 +23,7 @@ impl Connection {
}
/// once lose track, this [Connection] will never be tracked again
pub fn lose_track(mut self) -> Box<Self> {
self.id = "Lose Track, Maybe Closed".to_owned();
self.id = None;
Box::new(self)
}
pub fn build_header() -> Raw::Row<'static> {
Expand Down Expand Up @@ -79,7 +79,7 @@ impl From<clashtui::webapi::Conn> for Connection {
start,
upload,
download,
id,
id: Some(id),
}
}
}
Expand All @@ -96,7 +96,7 @@ fn t() {
start: "start time".to_owned(),
upload: 100,
download: 10000,
id: "id".to_owned(),
id: Some("id".to_owned()),
};
f.render_widget(&this, f.area())
}
Expand Down Expand Up @@ -270,10 +270,15 @@ impl Raw::WidgetRef for Connection {
.block(b_download.fg(Theme::get().popup_block_fg))
.fg(Theme::get().popup_text_fg)
.render(a_download, buf);
Paragraph::new(self.id.as_str())
.block(b_id.fg(Theme::get().popup_block_fg))
.fg(Theme::get().popup_text_fg)
.render(a_id, buf);
Paragraph::new(
self.id
.as_ref()
.map(|s| s.as_str())
.unwrap_or("Lose Track, Maybe Closed"),
)
.block(b_id.fg(Theme::get().popup_block_fg))
.fg(Theme::get().popup_text_fg)
.render(a_id, buf);
Paragraph::new("Press Enter to terminate this connection, Esc to close")
.block(b_promopt.fg(Theme::get().popup_block_fg))
.fg(Theme::get().popup_text_fg)
Expand Down

0 comments on commit 010e8cf

Please sign in to comment.