mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2025-12-23 14:21:28 -05:00
draft preview charts for each adapter in initial page
This commit is contained in:
@@ -54,7 +54,7 @@ pub fn update_charts_data(&mut self, packets: u128) {
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, Message, StyleType> {
|
||||
Column::new().push(ChartWidget::new(self)).into()
|
||||
Column::new().height(50).push(ChartWidget::new(self)).into()
|
||||
}
|
||||
|
||||
pub fn change_style(&mut self, style: StyleType) {
|
||||
@@ -120,7 +120,7 @@ fn build_chart<DB: DrawingBackend>(
|
||||
return;
|
||||
}
|
||||
|
||||
self.set_margins_and_label_areas(&mut chart_builder);
|
||||
// self.set_margins_and_label_areas(&mut chart_builder);
|
||||
|
||||
let x_axis_range = self.x_axis_range();
|
||||
let x_axis_start = x_axis_range.start;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use std::fmt::Write;
|
||||
|
||||
use crate::chart::types::preview_chart::PreviewChart;
|
||||
use crate::gui::components::button::button_open_file;
|
||||
use crate::gui::sniffer::Sniffer;
|
||||
use crate::gui::styles::button::ButtonType;
|
||||
@@ -232,6 +233,7 @@ fn get_col_adapter(
|
||||
} else {
|
||||
Some(Text::new(addrs).font(font))
|
||||
};
|
||||
let preview_chart = sniffer.preview_charts.get(name);
|
||||
scroll_adapters.push(
|
||||
Button::new(
|
||||
Column::new()
|
||||
@@ -243,7 +245,8 @@ fn get_col_adapter(
|
||||
.size(FONT_SIZE_SUBTITLE),
|
||||
)
|
||||
.push_maybe(subtitle.map(|sub| Text::new(sub).font(font)))
|
||||
.push_maybe(addrs_text),
|
||||
.push_maybe(addrs_text)
|
||||
.push_maybe(preview_chart.map(PreviewChart::view)),
|
||||
)
|
||||
.padding([20, 30])
|
||||
.width(Length::Fill)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::chart::types::preview_chart::PreviewChart;
|
||||
use crate::gui::components::footer::footer;
|
||||
use crate::gui::components::header::header;
|
||||
use crate::gui::components::modal::{get_clear_all_overlay, get_exit_overlay, modal};
|
||||
@@ -48,7 +49,7 @@
|
||||
use crate::mmdb::types::mmdb_reader::{MmdbReader, MmdbReaders};
|
||||
use crate::networking::parse_packets::BackendTrafficMessage;
|
||||
use crate::networking::parse_packets::parse_packets;
|
||||
use crate::networking::traffic_preview::{TrafficPreviews, traffic_preview};
|
||||
use crate::networking::traffic_preview::traffic_preview;
|
||||
use crate::networking::types::capture_context::{
|
||||
CaptureContext, CaptureSource, CaptureSourcePicklist, MyPcapImport,
|
||||
};
|
||||
@@ -101,8 +102,10 @@ pub struct Sniffer {
|
||||
pub pcap_error: Option<String>,
|
||||
/// Messages status
|
||||
pub dots_pulse: (String, u8),
|
||||
/// Chart displayed
|
||||
/// Traffic chart displayed in the Overview page
|
||||
pub traffic_chart: TrafficChart,
|
||||
/// Traffic preview charts displayed in the initial page
|
||||
pub preview_charts: HashMap<String, PreviewChart>,
|
||||
/// Currently displayed modal; None if no modal is displayed
|
||||
pub modal: Option<MyModal>,
|
||||
/// Currently displayed settings page; None if settings is closed
|
||||
@@ -131,8 +134,6 @@ pub struct Sniffer {
|
||||
pub freeze_tx: Option<tokio::sync::broadcast::Sender<()>>,
|
||||
/// Sender to freeze the traffic preview
|
||||
pub freeze_preview_tx: Option<tokio::sync::broadcast::Sender<()>>,
|
||||
/// Traffic previews for charts
|
||||
pub traffic_previews: TrafficPreviews,
|
||||
}
|
||||
|
||||
impl Sniffer {
|
||||
@@ -160,6 +161,7 @@ pub fn new(conf: Conf) -> Self {
|
||||
pcap_error: None,
|
||||
dots_pulse: (".".to_string(), 0),
|
||||
traffic_chart: TrafficChart::new(style, language, data_repr),
|
||||
preview_charts: HashMap::new(),
|
||||
modal: None,
|
||||
settings_page: None,
|
||||
running_page: None,
|
||||
@@ -177,7 +179,6 @@ pub fn new(conf: Conf) -> Self {
|
||||
frozen: false,
|
||||
freeze_tx: None,
|
||||
freeze_preview_tx: None,
|
||||
traffic_previews: TrafficPreviews::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,8 +636,19 @@ pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||
let _ = tx.send(());
|
||||
}
|
||||
}
|
||||
Message::TrafficPreview(preview) => {
|
||||
self.traffic_previews.refresh(preview);
|
||||
Message::TrafficPreview(msg) => {
|
||||
for (dev, packets) in msg.data {
|
||||
self.preview_charts
|
||||
.entry(dev)
|
||||
.and_modify(|chart| {
|
||||
chart.update_charts_data(packets);
|
||||
})
|
||||
.or_insert({
|
||||
let mut chart = PreviewChart::new(self.conf.settings.style);
|
||||
chart.update_charts_data(packets);
|
||||
chart
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
use crate::utils::error_logger::{ErrorLogger, Location};
|
||||
use async_channel::Sender;
|
||||
use pcap::Device;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::collections::HashMap;
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::sync::broadcast::Receiver;
|
||||
@@ -17,22 +17,6 @@ pub struct TrafficPreview {
|
||||
pub data: HashMap<String, u128>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct TrafficPreviews {
|
||||
pub data: HashMap<String, VecDeque<u128>>,
|
||||
}
|
||||
|
||||
impl TrafficPreviews {
|
||||
pub fn refresh(&mut self, msg: TrafficPreview) {
|
||||
for (dev, pkts) in msg.data {
|
||||
self.data
|
||||
.entry(dev)
|
||||
.and_modify(|v| v.push_back(pkts))
|
||||
.or_insert(VecDeque::from([pkts]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn traffic_preview(tx: &Sender<TrafficPreview>, freeze_rxs: (Receiver<()>, Receiver<()>)) {
|
||||
let (freeze_tx, mut freeze_rx) = tokio::sync::broadcast::channel(1_048_575);
|
||||
let (pcap_tx, pcap_rx) = std::sync::mpsc::sync_channel(10_000);
|
||||
|
||||
Reference in New Issue
Block a user