From 03806afde9039a62a74b5cc616ace12c2d79ea14 Mon Sep 17 00:00:00 2001 From: GyulyVGC Date: Fri, 27 Feb 2026 20:18:49 +0100 Subject: [PATCH] start testing program icons --- Cargo.lock | 58 ++++++++++++++++++++++++++ Cargo.toml | 1 + src/gui/pages/notifications_page.rs | 3 +- src/gui/pages/overview_page.rs | 10 ++++- src/networking/types/program_lookup.rs | 15 +++++++ 5 files changed, 84 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 701f711d..3b2830ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1057,6 +1057,27 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376" +[[package]] +name = "dirs" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.61.2", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -3446,6 +3467,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "orbclient" version = "0.3.50" @@ -3615,6 +3642,16 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" +[[package]] +name = "picon" +version = "0.0.0" +dependencies = [ + "image", + "objc2-app-kit 0.3.2", + "objc2-foundation 0.3.2", + "shellexpand", +] + [[package]] name = "pin-project" version = "1.1.10" @@ -4099,6 +4136,17 @@ dependencies = [ "bitflags 2.11.0", ] +[[package]] +name = "redox_users" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" +dependencies = [ + "getrandom 0.2.17", + "libredox", + "thiserror 2.0.18", +] + [[package]] name = "regex" version = "1.12.3" @@ -4645,6 +4693,15 @@ dependencies = [ "syn", ] +[[package]] +name = "shellexpand" +version = "3.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32824fab5e16e6c4d86dc1ba84489390419a39f97699852b66480bb87d297ed8" +dependencies = [ + "dirs", +] + [[package]] name = "shlex" version = "1.3.0" @@ -4813,6 +4870,7 @@ dependencies = [ "phf", "phf_codegen", "phf_shared", + "picon", "plotters", "plotters-iced2", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index 6c00d4ba..c17b44db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ maxminddb = "0.27.3" pcap = "2.4.0" phf = "0.13.1" phf_shared = "0.13.1" +picon = { path = "../picon" } plotters = { version = "0.3.7", default-features = false, features = ["area_series", "line_series"] } plotters-iced2 = "0.14.0" reqwest = { version = "0.13.2", features = ["json"] } diff --git a/src/gui/pages/notifications_page.rs b/src/gui/pages/notifications_page.rs index b2c1c4d7..d0adb292 100644 --- a/src/gui/pages/notifications_page.rs +++ b/src/gui/pages/notifications_page.rs @@ -36,7 +36,7 @@ use iced::widget::text::LineHeight; use iced::widget::tooltip::Position; use iced::widget::{Column, Container, Row, Scrollable, Text, Tooltip}; use iced::widget::{Space, button}; -use iced::{Alignment, Length, Padding}; +use iced::{Alignment, Element, Length, Padding}; use std::cmp::max; /// Computes the body of gui notifications page @@ -450,6 +450,7 @@ fn data_notification_extra<'a>( .1; for (service, data_info) in &logged_notification.services { let service_bar = simple_bar( + None::>, service.to_string(), data_info, logged_notification.data_repr, diff --git a/src/gui/pages/overview_page.rs b/src/gui/pages/overview_page.rs index 6adf1d27..3881af6b 100644 --- a/src/gui/pages/overview_page.rs +++ b/src/gui/pages/overview_page.rs @@ -26,7 +26,7 @@ use crate::networking::types::data_info::DataInfo; use crate::networking::types::data_info_host::DataInfoHost; use crate::networking::types::data_representation::DataRepr; use crate::networking::types::host::Host; -use crate::networking::types::program_lookup::ProgramLookup; +use crate::networking::types::program_lookup::{ProgramLookup, get_picon}; use crate::report::get_report_entries::{ get_host_entries, get_program_entries, get_service_entries, }; @@ -49,7 +49,9 @@ use iced::alignment::{Horizontal, Vertical}; use iced::widget::scrollable::Direction; use iced::widget::text::{LineHeight, Wrapping}; use iced::widget::tooltip::Position; -use iced::widget::{Button, Column, Container, Row, Scrollable, Space, Text, Tooltip, button}; +use iced::widget::{ + Button, Column, Container, Row, Scrollable, Space, Text, Tooltip, button, image, +}; use iced::{Alignment, Element, Length, Padding}; /// Computes the body of gui overview page @@ -215,6 +217,7 @@ fn col_service<'a>(sniffer: &Sniffer) -> Column<'a, Message, StyleType> { for (service, data_info) in &entries { let content = simple_bar( + None::>, service.to_string(), data_info, data_repr, @@ -278,6 +281,7 @@ fn col_program<'a>(conf: &Conf, program_lookup: &ProgramLookup) -> Column<'a, Me for (program, data_info) in &entries { let content = simple_bar( + image(&program_lookup.icon_handle).height(FLAGS_HEIGHT_BIG), program.to_string(), data_info, data_repr, @@ -360,6 +364,7 @@ pub fn host_bar<'a>( } pub fn simple_bar<'a>( + icon: impl Into>, item: String, data_info: &DataInfo, data_repr: DataRepr, @@ -372,6 +377,7 @@ pub fn simple_bar<'a>( .height(FLAGS_HEIGHT_BIG) .align_y(Alignment::Center) .spacing(5) + .push(icon) .push( Column::new() .spacing(1) diff --git a/src/networking/types/program_lookup.rs b/src/networking/types/program_lookup.rs index 33f2948d..85d360cf 100644 --- a/src/networking/types/program_lookup.rs +++ b/src/networking/types/program_lookup.rs @@ -1,9 +1,12 @@ +use crate::countries::flags_pictures::FLAGS_HEIGHT_BIG; use crate::networking::manage_packets::get_local_port; use crate::networking::types::address_port_pair::AddressPortPair; use crate::networking::types::data_info::DataInfo; use crate::networking::types::data_representation::DataRepr; use crate::networking::types::info_address_port_pair::InfoAddressPortPair; use crate::networking::types::program::Program; +use iced::widget::image::Handle; +use iced::widget::{Image, image}; use listeners::{Process, Protocol}; use std::collections::HashMap; use std::sync::mpsc::{Receiver, Sender}; @@ -17,6 +20,7 @@ pub struct ProgramLookup { program_rx: Receiver<(u16, Protocol, Option)>, state: HashMap<(u16, Protocol), LookedUpProgram>, programs: HashMap, + pub icon_handle: Handle, } impl ProgramLookup { @@ -29,6 +33,9 @@ impl ProgramLookup { program_rx, state: HashMap::new(), programs: HashMap::new(), + icon_handle: Handle::from_bytes( + picon::get_icon_by_path("/Applications/Telegram.app").bytes, + ), } } @@ -176,3 +183,11 @@ pub fn lookup_program( let _ = program_tx.send((port, protocol, program)); } } + +pub fn get_picon(program_lookup: &ProgramLookup) -> Image { + // let icon_bytes = picon::get_icon_by_path(ppath); + image(image::Handle::from_path( + "/Applications/Sniffnet.app/Contents/Resources/sniffnet.icns", + )) + .height(FLAGS_HEIGHT_BIG) +}