Skip to content

Commit

Permalink
wait amend
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackhr-arch committed Jul 1, 2024
1 parent dde9016 commit 0e69f71
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 12 deletions.
77 changes: 77 additions & 0 deletions clashtui/api/src/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"downloadTotal": 2668789,
"uploadTotal": 4179,
"connections": [
{
"id": "2661ce43-17bd-4c23-9c79-8369298c8fb3",
"metadata": {
"network": "tcp",
"type": "HTTPS",
"sourceIP": "127.0.0.1",
"destinationIP": "",
"destinationGeoIP": null,
"destinationIPASN": "",
"sourcePort": "39926",
"destinationPort": "443",
"inboundIP": "127.0.0.1",
"inboundPort": "7890",
"inboundName": "DEFAULT-MIXED",
"inboundUser": "",
"host": "objects.githubusercontent.com",
"dnsMode": "normal",
"uid": 0,
"process": "",
"processPath": "",
"specialProxy": "",
"specialRules": "",
"remoteDestination": "185.199.110.133",
"dscp": 0,
"sniffHost": ""
},
"upload": 1194,
"download": 2567632,
"start": "2024-06-30T09:20:17.386789854Z",
"chains": [
"DIRECT"
],
"rule": "",
"rulePayload": ""
},
{
"id": "59f12afb-719a-4d0c-a4b8-1ec78f604e9c",
"metadata": {
"network": "tcp",
"type": "HTTPS",
"sourceIP": "127.0.0.1",
"destinationIP": "",
"destinationGeoIP": null,
"destinationIPASN": "",
"sourcePort": "39916",
"destinationPort": "443",
"inboundIP": "127.0.0.1",
"inboundPort": "7890",
"inboundName": "DEFAULT-MIXED",
"inboundUser": "",
"host": "github.com",
"dnsMode": "normal",
"uid": 0,
"process": "",
"processPath": "",
"specialProxy": "",
"specialRules": "",
"remoteDestination": "20.205.243.166",
"dscp": 0,
"sniffHost": ""
},
"upload": 854,
"download": 7692,
"start": "2024-06-30T09:20:17.374233864Z",
"chains": [
"DIRECT"
],
"rule": "",
"rulePayload": ""
}
],
"memory": 0
}
10 changes: 6 additions & 4 deletions clashtui/backend/src/backend/impl_conn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::ClashBackend;

impl ClashBackend {
#[cfg(test)]
#[cfg(not(test))]
pub fn get_connections(&self) -> Result<(Option<Vec<Vec<String>>>, (u64, u64)), String> {
use crate::utils::bytes_to_readable;
Ok((
Expand All @@ -12,14 +12,15 @@ impl ClashBackend {
"DIRECT".to_string(),
"2024-06-30T09:20:17.386789854Z".to_string(),
bytes_to_readable(854),
bytes_to_readable(7652)
bytes_to_readable(7652),
"59f12afb-719a-4d0c-a4b8-1ec78f604e9c".to_string()
];
3
]),
(10000, 0),
))
}
#[cfg(not(test))]
#[cfg(test)]
pub fn get_connections(&self) -> Result<(Option<Vec<Vec<String>>>, (u64, u64)), String> {
use crate::utils::bytes_to_readable;
use api::{Conn, ConnInfo, ConnMetaData};
Expand All @@ -40,7 +41,7 @@ impl ClashBackend {
.flat_map(|t| t.into_iter())
.map(|c| {
let Conn {
id: _,
id,
metadata,
upload,
download,
Expand All @@ -66,6 +67,7 @@ impl ClashBackend {
start,
bytes_to_readable(upload),
bytes_to_readable(download),
id
]
})
.collect(),
Expand Down
7 changes: 7 additions & 0 deletions clashtui/backend/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ macro_rules! define_enum {
}
}
};
($(#[$attr:meta])*
$vis:vis $name: ident,
[$($variant:ident,)*]) => {
define_enum!($(#[$attr:meta])*
$vis:vis $name: ident,
[$($variant:ident),*])
};
}

#[cfg(target_os = "linux")]
Expand Down
9 changes: 8 additions & 1 deletion clashtui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::tui::{
use crate::utils::{ClashBackend, SharedBackend, SharedState, State};

use super::impl_app::MonkeyPatch;
use super::tabs::ConnctlTab;

pub struct App {
tabbar: TabBar,
Expand All @@ -38,6 +39,7 @@ impl App {
let tabs: Vec<Tabs> = vec![
Tabs::Profile(ProfileTab::new(util.clone(), state.clone())),
Tabs::ClashSrvCtl(ClashSrvCtlTab::new(util.clone(), state.clone())),
Tabs::ConnCtl(ConnctlTab::new(util.clone())),
]; // Init the tabs
let tabbar = TabBar::new(tabs.iter().map(|v| v.to_string()).collect());
let statusbar = StatusBar::new(Rc::clone(&state));
Expand Down Expand Up @@ -73,7 +75,7 @@ impl App {
.expect(backend::const_err::ERR_PATH_UTF_8)
));
};
if is_root::is_root(){
if is_root::is_root() {
self.popup_txt_msg(crate::utils::consts::ROOT_WARNING.to_string())
}
err_track
Expand Down Expand Up @@ -112,6 +114,7 @@ impl App {
let mut iter = self.tabs.iter_mut().map(|v| match v {
Tabs::Profile(tab) => tab.popup_event(ev),
Tabs::ClashSrvCtl(tab) => tab.popup_event(ev),
Tabs::ConnCtl(tab) => tab.popup_event(ev),
});
while event_state.is_notconsumed() {
match iter.next() {
Expand Down Expand Up @@ -194,6 +197,7 @@ impl App {
let mut iter = self.tabs.iter_mut().map(|v| match v {
Tabs::Profile(tab) => tab.event(ev),
Tabs::ClashSrvCtl(tab) => Ok(tab.event(ev)?),
Tabs::ConnCtl(tab) => Ok(tab.event(ev)?),
});
while event_state.is_notconsumed() {
match iter.next() {
Expand All @@ -210,6 +214,7 @@ impl App {
self.tabs.iter_mut().for_each(|v| match v {
Tabs::Profile(tab) => tab.late_event(),
Tabs::ClashSrvCtl(tab) => tab.late_event(),
Tabs::ConnCtl(tab) => tab.late_event(),
})
}

Expand All @@ -233,6 +238,7 @@ impl App {
self.tabs.iter_mut().for_each(|v| match v {
Tabs::Profile(tab) => tab.draw(f, tab_chunk),
Tabs::ClashSrvCtl(tab) => tab.draw(f, tab_chunk),
Tabs::ConnCtl(tab) => tab.draw(f, tab_chunk),
});

self.statusbar.draw(f, chunks[2]);
Expand All @@ -256,6 +262,7 @@ impl App {
.for_each(|(b, v)| match v {
Tabs::Profile(tab) => tab.set_visible(b),
Tabs::ClashSrvCtl(tab) => tab.set_visible(b),
Tabs::ConnCtl(tab) => tab.set_visible(b),
});
}
}
Expand Down
Loading

0 comments on commit 0e69f71

Please sign in to comment.