Skip to content

Commit

Permalink
removed unnecessary fields from logged notifications structs
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Feb 18, 2023
1 parent 697be1d commit e918c06
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/enums/logged_notification.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::structs::address_port_pair::AddressPortPair;
use crate::structs::info_address_port_pair::InfoAddressPortPair;
use crate::structs::notifications::{BytesNotification, PacketsNotification};
use crate::ByteMultiple;

/// Enum representing the possible observed values of IP protocol version.
pub enum LoggedNotification {
Expand All @@ -14,15 +14,16 @@ pub enum LoggedNotification {

#[derive(Clone)]
pub struct PacketsThresholdExceeded {
pub(crate) notification: PacketsNotification,
pub(crate) threshold: u32,
pub(crate) incoming: u32,
pub(crate) outgoing: u32,
pub(crate) timestamp: String,
}

#[derive(Clone)]
pub struct BytesThresholdExceeded {
pub(crate) notification: BytesNotification,
pub(crate) threshold: u64,
pub(crate) byte_multiple: ByteMultiple,
pub(crate) incoming: u32,
pub(crate) outgoing: u32,
pub(crate) timestamp: String,
Expand Down
17 changes: 4 additions & 13 deletions src/gui/pages/notifications_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,7 @@ fn packets_notification_log(
) -> Container<'static, Message> {
let font = get_font(style);
let mut threshold_str = threshold_translation(language);
threshold_str.push_str(
&logged_notification
.notification
.previous_threshold
.to_string(),
);
threshold_str.push_str(&logged_notification.threshold.to_string());
threshold_str.push_str(&format!(" {}", per_second_translation(language)));
let mut incoming_str = " - ".to_string();
incoming_str.push_str(incoming_translation(language));
Expand Down Expand Up @@ -253,16 +248,12 @@ fn bytes_notification_log(
let font = get_font(style);
let mut threshold_str = threshold_translation(language);
threshold_str.push_str(
&(logged_notification.notification.previous_threshold
/ logged_notification
.notification
.byte_multiple
.get_multiplier())
.to_string(),
&(logged_notification.threshold / logged_notification.byte_multiple.get_multiplier())
.to_string(),
);
threshold_str.push_str(&format!(
" {}",
logged_notification.notification.byte_multiple.get_char()
logged_notification.byte_multiple.get_char()
));
threshold_str.push_str(&format!(" {}", per_second_translation(language)));
let mut incoming_str = " - ".to_string();
Expand Down
5 changes: 3 additions & 2 deletions src/utility/manage_notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn notify_and_log(
}
runtime_data.logged_notifications.push_front(
LoggedNotification::PacketsThresholdExceeded(PacketsThresholdExceeded {
notification: notifications.packets_notification,
threshold: notifications.packets_notification.previous_threshold,
incoming: received_packets_entry.try_into().unwrap(),
outgoing: sent_packets_entry.try_into().unwrap(),
timestamp: Local::now().to_string().get(11..19).unwrap().to_string(),
Expand Down Expand Up @@ -58,7 +58,8 @@ pub fn notify_and_log(
}
runtime_data.logged_notifications.push_front(
LoggedNotification::BytesThresholdExceeded(BytesThresholdExceeded {
notification: notifications.bytes_notification,
threshold: notifications.bytes_notification.previous_threshold,
byte_multiple: notifications.bytes_notification.byte_multiple,
incoming: received_bytes_entry.try_into().unwrap(),
outgoing: sent_bytes_entry.try_into().unwrap(),
timestamp: Local::now().to_string().get(11..19).unwrap().to_string(),
Expand Down

0 comments on commit e918c06

Please sign in to comment.