mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2026-10-23 15:41:14 +00:00
get picons for saved favorite programs
This commit is contained in:
parent
d416bbe247
commit
bd3cd30237
3 changed files with 38 additions and 11 deletions
|
|
@ -41,6 +41,7 @@ use crate::networking::types::host::{Host, HostMessage};
|
|||
use crate::networking::types::info_traffic::InfoTraffic;
|
||||
use crate::networking::types::ip_blacklist::IpBlacklist;
|
||||
use crate::networking::types::my_device::MyDevice;
|
||||
use crate::networking::types::program::Program;
|
||||
use crate::networking::types::program_lookup::{ProgramLookup, get_picon, lookup_program};
|
||||
use crate::notifications::notify_and_log::notify_and_log;
|
||||
use crate::notifications::types::logged_notification::LoggedNotifications;
|
||||
|
|
@ -1018,10 +1019,12 @@ impl Sniffer {
|
|||
.log_err(location!());
|
||||
let (icon_key_tx, icon_key_rx) = std::sync::mpsc::channel();
|
||||
let (picon_tx, picon_rx) = std::sync::mpsc::channel();
|
||||
let favorite_programs: Vec<Program> =
|
||||
self.conf.favorites.programs().iter().cloned().collect();
|
||||
let _ = thread::Builder::new()
|
||||
.name("thread_get_picon".to_string())
|
||||
.spawn(move || {
|
||||
get_picon(&icon_key_rx, &picon_tx);
|
||||
get_picon(&icon_key_rx, &picon_tx, favorite_programs);
|
||||
})
|
||||
.log_err(location!());
|
||||
self.program_lookup = Some(ProgramLookup::new(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use crate::gui::sniffer::Sniffer;
|
|||
use crate::gui::styles::button::ButtonType;
|
||||
use crate::gui::styles::types::style_type::StyleType;
|
||||
use crate::gui::types::conf::Conf;
|
||||
use crate::gui::types::conf::deserialize_or_default;
|
||||
use crate::gui::types::message::Message;
|
||||
use crate::networking::types::data_info::DataInfo;
|
||||
use crate::networking::types::data_info_host::DataInfoHost;
|
||||
|
|
@ -27,9 +28,13 @@ use std::cmp::min;
|
|||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct Favorites {
|
||||
#[serde(deserialize_with = "deserialize_or_default")]
|
||||
hosts: HashSet<Host>,
|
||||
#[serde(deserialize_with = "deserialize_or_default")]
|
||||
services: HashSet<Service>,
|
||||
#[serde(deserialize_with = "deserialize_or_default")]
|
||||
programs: HashSet<Program>,
|
||||
}
|
||||
|
||||
|
|
@ -376,11 +381,13 @@ fn get_service_entries(
|
|||
})
|
||||
.collect()
|
||||
} else {
|
||||
info_traffic.services.iter().collect()
|
||||
info_traffic
|
||||
.services
|
||||
.iter()
|
||||
.filter(|(service, _)| service != &&Service::NotApplicable)
|
||||
.collect()
|
||||
};
|
||||
|
||||
sorted_vec.retain(|(service, _)| service != &&Service::NotApplicable);
|
||||
|
||||
sorted_vec.sort_by(|&(_, a), &(_, b)| a.compare(b, sort_type, data_repr));
|
||||
|
||||
let n_entry = min(sorted_vec.len(), 30);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use iced::widget::tooltip::Position;
|
|||
use iced::widget::{Image, Svg, Text, Tooltip, svg};
|
||||
use listeners::{Process, Protocol};
|
||||
use picon::IconHandle;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use std::time::Instant;
|
||||
|
||||
|
|
@ -136,9 +136,7 @@ impl ProgramLookup {
|
|||
if !self.picons.contains_key(icon_key) {
|
||||
self.picons
|
||||
.insert(icon_key.to_string(), DEFAULT_PICON.clone());
|
||||
if !icon_key.is_empty() {
|
||||
let _ = self.icon_key_tx.send(icon_key.to_string());
|
||||
}
|
||||
let _ = self.icon_key_tx.send(icon_key.to_string());
|
||||
}
|
||||
|
||||
// associate unassigned recent connections on port with the program
|
||||
|
|
@ -242,11 +240,30 @@ pub fn lookup_program(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_picon(icon_key_rx: &Receiver<String>, picon_tx: &Sender<(String, IconHandle)>) {
|
||||
while let Ok(icon_key) = icon_key_rx.recv() {
|
||||
if let Some(handle) = picon::get_icon(&icon_key) {
|
||||
pub fn get_picon(
|
||||
icon_key_rx: &Receiver<String>,
|
||||
picon_tx: &Sender<(String, IconHandle)>,
|
||||
favorite_programs: Vec<Program>,
|
||||
) {
|
||||
let mut unique_icon_keys = HashSet::new();
|
||||
|
||||
let mut get_and_send_picon = |icon_key: String| {
|
||||
if !icon_key.is_empty()
|
||||
&& unique_icon_keys.insert(icon_key.clone())
|
||||
&& let Some(handle) = picon::get_icon(&icon_key)
|
||||
{
|
||||
let _ = picon_tx.send((icon_key, handle));
|
||||
}
|
||||
};
|
||||
|
||||
// first get picons for saved favorite programs
|
||||
for program in favorite_programs {
|
||||
let icon_key = program.icon_key().to_string();
|
||||
get_and_send_picon(icon_key);
|
||||
}
|
||||
|
||||
while let Ok(icon_key) = icon_key_rx.recv() {
|
||||
get_and_send_picon(icon_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue