diff --git a/Cargo.toml b/Cargo.toml index f757b727..5de3df10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ iced_lazy = "0.6.1" plotters-iced = "0.8.0" maxminddb = "0.23.0" confy = "0.5.1" -serde = { version = "1.0.163", default_features = false, features = ["derive"] } +serde = { version = "1.0.163", default_features = false, features = ["derive", "rc"] } rodio = { version = "0.17.1", default_features = false, features = ["mp3"] } reqwest = { version = "0.11.18", default-features = false, features = ["json", "blocking", "rustls-tls"] } dns-lookup = "2.0.2" diff --git a/resources/themes/catppuccin_mocha.toml b/resources/themes/catppuccin_mocha.toml index e3885a5a..78e0e83b 100644 --- a/resources/themes/catppuccin_mocha.toml +++ b/resources/themes/catppuccin_mocha.toml @@ -19,3 +19,4 @@ round_borders = "#74c7ec" # Sapphire round_containers = "#585b70" # Surface 2 starred = "#f9e2af" # Yellow badge_alpha = 0.75 +color_mix_chart = 0.3 diff --git a/src/chart/types/traffic_chart.rs b/src/chart/types/traffic_chart.rs index bf4d7810..fb996ac9 100644 --- a/src/chart/types/traffic_chart.rs +++ b/src/chart/types/traffic_chart.rs @@ -46,7 +46,7 @@ pub struct TrafficChart { } impl TrafficChart { - pub fn new(style: StyleType, language: Language) -> Self { + pub fn new(style: &StyleType, language: Language) -> Self { TrafficChart { ticks: 0, sent_bytes: VecDeque::default(), @@ -89,7 +89,7 @@ impl TrafficChart { self.language = language; } - pub fn change_colors(&mut self, style: StyleType) { + pub fn change_colors(&mut self, style: &StyleType) { self.color_font = to_rgb_color(get_colors(style).text_body); self.color_incoming = to_rgb_color(get_colors(style).incoming); self.color_outgoing = to_rgb_color(get_colors(style).outgoing); diff --git a/src/configs/types/config_settings.rs b/src/configs/types/config_settings.rs index 0f553339..22aef7f5 100644 --- a/src/configs/types/config_settings.rs +++ b/src/configs/types/config_settings.rs @@ -1,6 +1,8 @@ //! Module defining the `ConfigSettings` struct, which allows to save and reload //! the application default configuration. +use std::sync::Arc; + use serde::{Deserialize, Serialize}; use crate::notifications::types::notifications::Notifications; @@ -8,7 +10,7 @@ use crate::{Language, StyleType}; #[derive(Serialize, Deserialize, Default)] pub struct ConfigSettings { - pub style: StyleType, + pub style: Arc, pub language: Language, pub notifications: Notifications, } diff --git a/src/countries/country_utils.rs b/src/countries/country_utils.rs index decd1367..8a8ed893 100644 --- a/src/countries/country_utils.rs +++ b/src/countries/country_utils.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use iced::widget::Tooltip; use iced::{Length, Renderer}; use iced_native::svg::Handle; @@ -332,16 +334,16 @@ pub fn get_flag_tooltip( is_local: bool, traffic_type: TrafficType, language: Language, - style: StyleType, + style: &Arc, ) -> Tooltip<'static, Message> { let (content, tooltip) = get_flag_from_country(country, width, is_local, traffic_type, language); let mut tooltip = Tooltip::new(content, tooltip, Position::FollowCursor) - .font(get_font(style)) + .font(get_font(&style)) .snap_within_viewport(true) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )); if width == FLAGS_WIDTH_SMALL { @@ -355,7 +357,7 @@ pub fn get_computer_tooltip( is_my_address: bool, traffic_type: TrafficType, language: Language, - style: StyleType, + style: &Arc, ) -> Tooltip<'static, Message> { let content = Svg::new(Handle::from_memory(Vec::from( match (is_my_address, traffic_type) { @@ -376,9 +378,9 @@ pub fn get_computer_tooltip( }; Tooltip::new(content, tooltip, Position::FollowCursor) - .font(get_font(style)) + .font(get_font(&style)) .snap_within_viewport(true) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )) } diff --git a/src/gui/app.rs b/src/gui/app.rs index 6e32b303..f79b8f68 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -49,12 +49,12 @@ impl Application for Sniffer { fn view(&self) -> Element { let status = *self.status_pair.0.lock().unwrap(); - let style = self.style; - let font = get_font(style); + let style = &self.style; + let font = get_font(&style); let header = match status { - Status::Init => header(style, false, self.language, self.last_opened_setting), - Status::Running => header(style, true, self.language, self.last_opened_setting), + Status::Init => header(&style, false, self.language, self.last_opened_setting), + Status::Running => header(&style, true, self.language, self.last_opened_setting), }; let body = match status { @@ -66,7 +66,7 @@ impl Application for Sniffer { }, }; - let footer = footer(self.language, style, &self.newer_release_available.clone()); + let footer = footer(self.language, &style, &self.newer_release_available.clone()); let content = Column::new().push(header).push(body).push(footer); @@ -88,8 +88,8 @@ impl Application for Sniffer { } Some(modal) => { let overlay = match modal { - MyModal::Quit => get_exit_overlay(style, font, self.language), - MyModal::ClearAll => get_clear_all_overlay(style, font, self.language), + MyModal::Quit => get_exit_overlay(&style, font, self.language), + MyModal::ClearAll => get_clear_all_overlay(&style, font, self.language), MyModal::ConnectionDetails(connection_index) => { connection_details_page(self, connection_index) } diff --git a/src/gui/components/footer.rs b/src/gui/components/footer.rs index 5aa3f149..3c2656c4 100644 --- a/src/gui/components/footer.rs +++ b/src/gui/components/footer.rs @@ -22,7 +22,7 @@ use crate::Language; pub fn footer( language: Language, - style: StyleType, + style: &Arc, newer_release_available: &Arc>>, ) -> Container<'static, Message> { let font_footer = get_font_headers(style); @@ -53,11 +53,11 @@ pub fn footer( .align_y(Vertical::Center) .align_x(Horizontal::Center) .style(>::into( - StyleTuple(style, ElementType::Headers), + StyleTuple(Arc::clone(style), ElementType::Headers), )) } -fn get_button_website(style: StyleType) -> Tooltip<'static, Message> { +fn get_button_website(style: &Arc) -> Tooltip<'static, Message> { let content = button( Text::new('c'.to_string()) .font(ICONS) @@ -67,17 +67,17 @@ fn get_button_website(style: StyleType) -> Tooltip<'static, Message> { ) .height(Length::Fixed(30.0)) .width(Length::Fixed(30.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::OpenWebPage(WebPage::Website)); Tooltip::new(content, "Website", Position::Top) - .font(get_font(style)) + .font(get_font(&style)) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )) } -fn get_button_github(style: StyleType) -> Tooltip<'static, Message> { +fn get_button_github(style: &Arc) -> Tooltip<'static, Message> { let content = button( Text::new('H'.to_string()) .font(ICONS) @@ -87,17 +87,17 @@ fn get_button_github(style: StyleType) -> Tooltip<'static, Message> { ) .height(Length::Fixed(40.0)) .width(Length::Fixed(40.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::OpenWebPage(WebPage::Repo)); Tooltip::new(content, "GitHub", Position::Top) .font(get_font(style)) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )) } -fn get_button_sponsor(style: StyleType) -> Tooltip<'static, Message> { +fn get_button_sponsor(style: &Arc) -> Tooltip<'static, Message> { let content = button( Text::new('❤'.to_string()) .size(28) @@ -107,19 +107,19 @@ fn get_button_sponsor(style: StyleType) -> Tooltip<'static, Message> { ) .height(Length::Fixed(30.0)) .width(Length::Fixed(30.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::OpenWebPage(WebPage::Sponsor)); Tooltip::new(content, "Sponsor", Position::Top) .font(get_font(style)) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )) } fn get_release_details( language: Language, - style: StyleType, + style: &Arc, font_footer: Font, newer_release_available: &Arc>>, ) -> Row<'static, Message> { @@ -146,7 +146,7 @@ fn get_release_details( .padding(5) .height(Length::Fixed(35.0)) .width(Length::Fixed(35.0)) - .style(StyleTuple(style, ElementType::Alert).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Alert).into()) .on_press(Message::OpenWebPage(WebPage::WebsiteDownload)); let tooltip = Tooltip::new( button, @@ -155,7 +155,7 @@ fn get_release_details( ) .font(get_font(style)) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )); ret_val = ret_val .push(horizontal_space(Length::Fixed(10.0))) diff --git a/src/gui/components/header.rs b/src/gui/components/header.rs index c976f1cb..c31e907e 100644 --- a/src/gui/components/header.rs +++ b/src/gui/components/header.rs @@ -1,5 +1,7 @@ //! GUI upper header +use std::sync::Arc; + use iced::alignment::{Horizontal, Vertical}; use iced::widget::{button, Container, Row, Text, Tooltip}; use iced::Length::FillPortion; @@ -15,7 +17,7 @@ use crate::translations::translations::{quit_analysis_translation, settings_tran use crate::{Language, StyleType}; pub fn header( - style: StyleType, + style: &Arc, back_button: bool, language: Language, last_opened_setting: SettingsPage, @@ -61,11 +63,11 @@ pub fn header( .align_y(Vertical::Center) .width(Length::Fill) .style(>::into( - StyleTuple(style, ElementType::Headers), + StyleTuple(Arc::clone(style), ElementType::Headers), )) } -fn get_button_reset(style: StyleType, language: Language) -> Tooltip<'static, Message> { +fn get_button_reset(style: &Arc, language: Language) -> Tooltip<'static, Message> { let content = button( Text::new('C'.to_string()) .font(ICONS) @@ -76,7 +78,7 @@ fn get_button_reset(style: StyleType, language: Language) -> Tooltip<'static, Me .padding(10) .height(Length::Fixed(40.0)) .width(Length::Fixed(60.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::ResetButtonPressed); Tooltip::new( @@ -86,12 +88,12 @@ fn get_button_reset(style: StyleType, language: Language) -> Tooltip<'static, Me ) .font(get_font(style)) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )) } pub fn get_button_settings( - style: StyleType, + style: &Arc, language: Language, open_overlay: SettingsPage, ) -> Tooltip<'static, Message> { @@ -104,12 +106,12 @@ pub fn get_button_settings( .padding(10) .height(Length::Fixed(40.0)) .width(Length::Fixed(60.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::OpenSettings(open_overlay)); Tooltip::new(content, settings_translation(language), Position::Left) .font(get_font(style)) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )) } diff --git a/src/gui/components/modal.rs b/src/gui/components/modal.rs index 24b1c4fc..6eee9a7b 100644 --- a/src/gui/components/modal.rs +++ b/src/gui/components/modal.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use iced::alignment::{Alignment, Horizontal, Vertical}; use iced::widget::{ button, horizontal_space, vertical_space, Column, Container, Row, Text, Tooltip, @@ -18,7 +20,7 @@ use crate::translations::translations::{ use crate::{Language, StyleType}; pub fn get_exit_overlay( - style: StyleType, + style: &Arc, font: Font, language: Language, ) -> Container<'static, Message> { @@ -45,12 +47,12 @@ pub fn get_exit_overlay( .height(Length::Fixed(160.0)) .width(Length::Fixed(450.0)) .style(>::into( - StyleTuple(style, ElementType::Standard), + StyleTuple(Arc::clone(style), ElementType::Standard), )) } pub fn get_clear_all_overlay( - style: StyleType, + style: &Arc, font: Font, language: Language, ) -> Container<'static, Message> { @@ -77,12 +79,12 @@ pub fn get_clear_all_overlay( .height(Length::Fixed(160.0)) .width(Length::Fixed(450.0)) .style(>::into( - StyleTuple(style, ElementType::Standard), + StyleTuple(Arc::clone(style), ElementType::Standard), )) } fn get_modal_header( - style: StyleType, + style: &Arc, language: Language, title: String, ) -> Container<'static, Message> { @@ -111,14 +113,14 @@ fn get_modal_header( .padding(2) .height(Length::Fixed(20.0)) .width(Length::Fixed(20.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::HideModal), tooltip, Position::Right, ) .font(font) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )), ) .width(Length::FillPortion(1)) @@ -130,14 +132,14 @@ fn get_modal_header( .height(Length::Fixed(40.0)) .width(Length::Fill) .style(>::into( - StyleTuple(style, ElementType::Headers), + StyleTuple(Arc::clone(style), ElementType::Headers), )) } fn confirm_button_row( language: Language, font: Font, - style: StyleType, + style: &Arc, message: Message, ) -> Row<'static, Message> { Row::new() @@ -153,7 +155,7 @@ fn confirm_button_row( .padding(5) .height(Length::Fixed(40.0)) .width(Length::Fixed(80.0)) - .style(StyleTuple(style, ElementType::Alert).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Alert).into()) .on_press(message), ) } diff --git a/src/gui/components/radio.rs b/src/gui/components/radio.rs index c79080af..72d822ac 100644 --- a/src/gui/components/radio.rs +++ b/src/gui/components/radio.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use iced::widget::{Column, Radio, Row, Text}; use iced::{Alignment, Font, Length}; use iced_native::widget::horizontal_space; @@ -18,7 +20,7 @@ use crate::{ChartType, IpVersion, Language, StyleType, TransProtocol}; pub fn ip_version_radios( active: IpVersion, font: Font, - style: StyleType, + style: &Arc, language: Language, ) -> Column<'static, Message> { let mut ret_val = Column::new().spacing(10).padding(0).push( @@ -38,7 +40,7 @@ pub fn ip_version_radios( .font(font) .size(15) .style(>::into(StyleTuple( - style, + Arc::clone(style), ElementType::Standard, ))), ); @@ -49,7 +51,7 @@ pub fn ip_version_radios( pub fn transport_protocol_radios( active: TransProtocol, font: Font, - style: StyleType, + style: &Arc, language: Language, ) -> Column<'static, Message> { let mut ret_val = Column::new().spacing(10).push( @@ -69,7 +71,7 @@ pub fn transport_protocol_radios( .font(font) .size(15) .style(>::into(StyleTuple( - style, + Arc::clone(style), ElementType::Standard, ))), ); @@ -81,7 +83,7 @@ pub fn language_radios( active: Language, collection: &[Language], font: Font, - style: StyleType, + style: &Arc, ) -> Row<'static, Message> { let mut ret_val = Row::new().spacing(10); for option in collection { @@ -101,7 +103,7 @@ pub fn language_radios( .size(15) .style( >::into(StyleTuple( - style, + Arc::clone(style), ElementType::Standard, )), ), @@ -117,7 +119,7 @@ pub fn language_radios( pub fn sound_packets_threshold_radios( packets_notification: PacketsNotification, font: Font, - style: StyleType, + style: &Arc, language: Language, ) -> Row<'static, Message> { let mut ret_val = Row::new() @@ -143,7 +145,7 @@ pub fn sound_packets_threshold_radios( .font(font) .size(15) .style(>::into(StyleTuple( - style, + Arc::clone(style), ElementType::Standard, ))), ); @@ -154,7 +156,7 @@ pub fn sound_packets_threshold_radios( pub fn sound_bytes_threshold_radios( bytes_notification: BytesNotification, font: Font, - style: StyleType, + style: &Arc, language: Language, ) -> Row<'static, Message> { let mut ret_val = Row::new() @@ -180,7 +182,7 @@ pub fn sound_bytes_threshold_radios( .font(font) .size(15) .style(>::into(StyleTuple( - style, + Arc::clone(style), ElementType::Standard, ))), ); @@ -191,7 +193,7 @@ pub fn sound_bytes_threshold_radios( pub fn sound_favorite_radios( favorite_notification: FavoriteNotification, font: Font, - style: StyleType, + style: &Arc, language: Language, ) -> Row<'static, Message> { let mut ret_val = Row::new() @@ -217,7 +219,7 @@ pub fn sound_favorite_radios( .font(font) .size(15) .style(>::into(StyleTuple( - style, + Arc::clone(style), ElementType::Standard, ))), ); @@ -228,7 +230,7 @@ pub fn sound_favorite_radios( pub fn chart_radios( active: ChartType, font: Font, - style: StyleType, + style: &Arc, language: Language, ) -> Column<'static, Message> { let mut ret_val = Column::new() @@ -247,7 +249,7 @@ pub fn chart_radios( .font(font) .size(15) .style(>::into(StyleTuple( - style, + Arc::clone(style), ElementType::Standard, ))), ); @@ -258,7 +260,7 @@ pub fn chart_radios( // pub fn report_radios( // active: ReportType, // font: Font, -// style: StyleType, +// style: Arc, // language: Language, // ) -> Row<'static, Message> { // let mut ret_val = Row::new() @@ -282,7 +284,7 @@ pub fn chart_radios( // .font(font) // .size(15) // .style(>::into(StyleTuple( -// style, +// Arc::clone(style), // ElementType::Standard, // ))), // ); diff --git a/src/gui/components/tab.rs b/src/gui/components/tab.rs index 62d5e73a..aeb328e0 100644 --- a/src/gui/components/tab.rs +++ b/src/gui/components/tab.rs @@ -1,4 +1,5 @@ //! Tab buttons to be used in the various pages just under the header +use std::sync::Arc; use iced::widget::{button, horizontal_space, Button, Row, Text}; use iced::{alignment, Alignment, Font, Length}; @@ -15,7 +16,7 @@ pub fn get_settings_tabs( icons: &[&str], actions: &[Message], active: SettingsPage, - style: StyleType, + style: &Arc, language: Language, ) -> Row<'static, Message> { let font = get_font(style); @@ -43,7 +44,7 @@ pub fn get_pages_tabs( icons: &[&str], actions: &[Message], active: RunningPage, - style: StyleType, + style: &Arc, language: Language, unread_notifications: usize, ) -> Row<'static, Message> { @@ -77,7 +78,7 @@ fn new_tab( icon: String, action: Message, active: bool, - style: StyleType, + style: &Arc, font: Font, unread: Option, ) -> Button<'static, Message> { @@ -110,7 +111,7 @@ fn new_tab( ) .padding(4) .height(Length::Fixed(20.0)) - .style(StyleTuple(style, ElementType::Badge).into()); + .style(StyleTuple(Arc::clone(style), ElementType::Badge).into()); content = content .push(horizontal_space(Length::Fixed(7.0))) .push(notifications_badge); @@ -124,7 +125,7 @@ fn new_tab( .width(Length::FillPortion(1)) .style( StyleTuple( - style, + Arc::clone(style), if active { ElementType::TabActive } else { diff --git a/src/gui/pages/connection_details_page.rs b/src/gui/pages/connection_details_page.rs index 6238b836..7cb4a6af 100644 --- a/src/gui/pages/connection_details_page.rs +++ b/src/gui/pages/connection_details_page.rs @@ -1,4 +1,4 @@ -use std::net::IpAddr; +use std::{net::IpAddr, sync::Arc}; use iced::alignment::{Horizontal, Vertical}; use iced::widget::{Column, Container, Row, Text, Tooltip}; @@ -38,7 +38,7 @@ pub fn connection_details_page(sniffer: &Sniffer, connection_index: usize) -> Co } fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static, Message> { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let info_traffic_lock = sniffer .info_traffic @@ -61,7 +61,7 @@ fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static let header_and_content = Column::new() .width(Length::Fill) - .push(page_header(sniffer.style, sniffer.language)); + .push(page_header(&sniffer.style, sniffer.language)); let mut source_caption = Row::new().spacing(10).push( Text::new(source_translation(sniffer.language)) @@ -82,7 +82,7 @@ fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static host_info.is_local, host_info.traffic_type, sniffer.language, - sniffer.style, + &sniffer.style, ); if address_to_lookup.eq(&key.address1) { source_caption = source_caption.push(flag); @@ -95,7 +95,7 @@ fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static TrafficDirection::Outgoing, ), sniffer.language, - sniffer.style, + &sniffer.style, ); dest_caption = dest_caption.push(computer); } else { @@ -109,7 +109,7 @@ fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static TrafficDirection::Outgoing, ), sniffer.language, - sniffer.style, + &sniffer.style, ); source_caption = source_caption.push(computer); } @@ -118,7 +118,7 @@ fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static host_info_col.push(Rule::horizontal(10.0).style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), ))); } if r_dns.parse::().is_err() { @@ -152,7 +152,7 @@ fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static ) .push( Rule::horizontal(10.0).style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )), ) .push( @@ -180,7 +180,7 @@ fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static ) .push( Rule::horizontal(10.0).style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )), ) .push( @@ -210,14 +210,14 @@ fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static .padding(10) .width(Length::Fill) .style(>::into( - StyleTuple(sniffer.style, ElementType::BorderedRound), + StyleTuple(Arc::clone(&sniffer.style), ElementType::BorderedRound), )); let dest_container = Container::new(dest_col) .padding(10) .width(Length::Fill) .style(>::into( - StyleTuple(sniffer.style, ElementType::BorderedRound), + StyleTuple(Arc::clone(&sniffer.style), ElementType::BorderedRound), )); let col_info = Column::new() @@ -291,11 +291,11 @@ fn page_content(sniffer: &Sniffer, connection_index: usize) -> Container<'static .width(Length::Fixed(1000.0)) .height(Length::Fixed(500.0)) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )) } -fn page_header(style: StyleType, language: Language) -> Container<'static, Message> { +fn page_header(style: &Arc, language: Language) -> Container<'static, Message> { let font = get_font(style); let tooltip = hide_translation(language).to_string(); Container::new( @@ -320,14 +320,14 @@ fn page_header(style: StyleType, language: Language) -> Container<'static, Messa .padding(2) .height(Fixed(20.0)) .width(Fixed(20.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::HideModal), tooltip, Position::Right, ) .font(font) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )), ) .width(Length::FillPortion(1)) @@ -339,6 +339,6 @@ fn page_header(style: StyleType, language: Language) -> Container<'static, Messa .height(Fixed(40.0)) .width(Length::Fill) .style(>::into( - StyleTuple(style, ElementType::Headers), + StyleTuple(Arc::clone(style), ElementType::Headers), )) } diff --git a/src/gui/pages/initial_page.rs b/src/gui/pages/initial_page.rs index f404a389..35958ee5 100644 --- a/src/gui/pages/initial_page.rs +++ b/src/gui/pages/initial_page.rs @@ -2,6 +2,8 @@ //! //! It contains elements to select network adapter and traffic filters. +use std::sync::Arc; + use iced::widget::{ button, horizontal_space, vertical_space, Button, Column, Container, PickList, Row, Scrollable, Text, Tooltip, @@ -25,12 +27,12 @@ use crate::{AppProtocol, Language, StyleType}; /// Computes the body of gui initial page pub fn initial_page(sniffer: &Sniffer) -> Container { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let col_adapter = get_col_adapter(sniffer, font); let ip_active = sniffer.filters.ip; - let col_ip_radio = ip_version_radios(ip_active, font, sniffer.style, sniffer.language); + let col_ip_radio = ip_version_radios(ip_active, font, &sniffer.style, sniffer.language); let col_ip = Column::new() .spacing(10) .width(FillPortion(5)) @@ -38,14 +40,14 @@ pub fn initial_page(sniffer: &Sniffer) -> Container { let transport_active = sniffer.filters.transport; let col_transport_radio = - transport_protocol_radios(transport_active, font, sniffer.style, sniffer.language); + transport_protocol_radios(transport_active, font, &sniffer.style, sniffer.language); let col_transport = Column::new() .align_items(Alignment::Center) .spacing(10) .width(FillPortion(9)) .push(col_transport_radio) .push(vertical_space(FillPortion(2))) - .push(button_start(sniffer.style, sniffer.language)) + .push(button_start(&sniffer.style, sniffer.language)) .push(vertical_space(FillPortion(1))); let app_active = if sniffer.filters.application.ne(&AppProtocol::Other) { @@ -65,7 +67,10 @@ pub fn initial_page(sniffer: &Sniffer) -> Container { .padding([3, 7]) .placeholder(all_translation(sniffer.language)) .font(font) - .style(StyleTuple(sniffer.style, ElementType::Standard)); + .style(StyleTuple( + Arc::clone(&sniffer.style), + ElementType::Standard, + )); let col_app = Column::new() .width(FillPortion(8)) .spacing(10) @@ -105,13 +110,13 @@ pub fn initial_page(sniffer: &Sniffer) -> Container { Container::new(body).height(Length::Fill).style( >::into(StyleTuple( - sniffer.style, + Arc::clone(&sniffer.style), ElementType::Standard, )), ) } -fn button_start(style: StyleType, language: Language) -> Tooltip<'static, Message> { +fn button_start(style: &Arc, language: Language) -> Tooltip<'static, Message> { let content = button( Text::new("S") .font(ICONS) @@ -122,7 +127,7 @@ fn button_start(style: StyleType, language: Language) -> Tooltip<'static, Messag .padding(10) .height(Length::Fixed(80.0)) .width(Length::Fixed(160.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::Start); let tooltip = start_translation(language).to_string(); @@ -131,7 +136,7 @@ fn button_start(style: StyleType, language: Language) -> Tooltip<'static, Messag .gap(5) .font(get_font(style)) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )) } @@ -190,7 +195,7 @@ fn get_col_adapter(sniffer: &Sniffer, font: Font) -> Column { .width(Length::Fill) .style( StyleTuple( - sniffer.style, + Arc::clone(&sniffer.style), if name == sniffer.device.name { ElementType::BorderedRoundSelected } else { @@ -204,7 +209,7 @@ fn get_col_adapter(sniffer: &Sniffer, font: Font) -> Column { }, )) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )), ) } diff --git a/src/gui/pages/inspect_page.rs b/src/gui/pages/inspect_page.rs index 7390f3e3..644bc453 100644 --- a/src/gui/pages/inspect_page.rs +++ b/src/gui/pages/inspect_page.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use iced::alignment::Horizontal; use iced::widget::{ Button, Checkbox, Column, Container, PickList, Row, Scrollable, Text, TextInput, Tooltip, @@ -27,7 +29,7 @@ use crate::{Language, ReportSortType, RunningPage, Sniffer, StyleType}; /// Computes the body of gui inspect page pub fn inspect_page(sniffer: &Sniffer) -> Container { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let mut body = Column::new() .width(Length::Fill) @@ -50,7 +52,7 @@ pub fn inspect_page(sniffer: &Sniffer) -> Container { Message::ChangeRunningPage(RunningPage::Notifications), ], RunningPage::Inspect, - sniffer.style, + &sniffer.style, sniffer.language, sniffer.unread_notifications, ); @@ -76,12 +78,15 @@ pub fn inspect_page(sniffer: &Sniffer) -> Container { ) .padding([3, 7]) .font(font) - .style(StyleTuple(sniffer.style, ElementType::Standard)); + .style(StyleTuple( + Arc::clone(&sniffer.style), + ElementType::Standard, + )); let report = lazy( ( sniffer.runtime_data.tot_sent_packets + sniffer.runtime_data.tot_received_packets, - sniffer.style, + Arc::clone(&sniffer.style), sniffer.language, sniffer.report_sort_type, sniffer.search.clone(), @@ -96,12 +101,12 @@ pub fn inspect_page(sniffer: &Sniffer) -> Container { Row::new() .push(filters_col( &sniffer.search, - sniffer.style, + &sniffer.style, sniffer.language, )) .push( Rule::vertical(25).style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )), ) .push( @@ -118,7 +123,7 @@ pub fn inspect_page(sniffer: &Sniffer) -> Container { .height(Length::Fixed(160.0)) .padding(10) .style(>::into( - StyleTuple(sniffer.style, ElementType::BorderedRound), + StyleTuple(Arc::clone(&sniffer.style), ElementType::BorderedRound), )), ) .push(report); @@ -126,12 +131,12 @@ pub fn inspect_page(sniffer: &Sniffer) -> Container { Container::new(Column::new().push(tab_and_body.push(body))) .height(Length::Fill) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )) } fn lazy_report(sniffer: &Sniffer) -> Row<'static, Message> { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let (search_results, results_number) = get_searched_entries(sniffer); @@ -142,7 +147,7 @@ fn lazy_report(sniffer: &Sniffer) -> Row<'static, Message> { col_report = col_report .push(Text::new(" Src IP address Src port Dst IP address Dst port Layer4 Layer7 Packets Bytes Country").font(font)) .push(Rule::horizontal(20).style(>::into(StyleTuple( - sniffer.style, + Arc::clone(&sniffer.style), ElementType::Standard, )))) ; @@ -150,7 +155,7 @@ fn lazy_report(sniffer: &Sniffer) -> Row<'static, Message> { let start_entry_num = (sniffer.page_number - 1) * 20 + 1; let end_entry_num = start_entry_num + search_results.len() - 1; for (key, val, flag) in search_results { - let entry_color = get_connection_color(val.traffic_direction, sniffer.style); + let entry_color = get_connection_color(val.traffic_direction, &sniffer.style); let entry_row = Row::new() .align_items(Alignment::Center) .push( @@ -165,7 +170,7 @@ fn lazy_report(sniffer: &Sniffer) -> Row<'static, Message> { button(entry_row) .padding(2) .on_press(Message::ShowModal(MyModal::ConnectionDetails(val.index))) - .style(StyleTuple(sniffer.style, ElementType::Neutral).into()), + .style(StyleTuple(Arc::clone(&sniffer.style), ElementType::Neutral).into()), ); } if results_number > 0 { @@ -176,16 +181,16 @@ fn lazy_report(sniffer: &Sniffer) -> Row<'static, Message> { .width(Length::Fill) .horizontal_scroll(Properties::new()) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )), ) .push( Rule::horizontal(20).style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )), ) .push(get_change_page_row( - sniffer.style, + &sniffer.style, sniffer.language, sniffer.page_number, start_entry_num, @@ -217,12 +222,12 @@ fn lazy_report(sniffer: &Sniffer) -> Row<'static, Message> { .padding([10, 7, 7, 7]) .width(Length::Fixed(1042.0)) .style(>::into( - StyleTuple(sniffer.style, ElementType::BorderedRound), + StyleTuple(Arc::clone(&sniffer.style), ElementType::BorderedRound), )), ) .push( Container::new(get_button_open_report( - sniffer.style, + &sniffer.style, sniffer.language, font, )) @@ -232,10 +237,10 @@ fn lazy_report(sniffer: &Sniffer) -> Row<'static, Message> { fn filters_col( search_params: &SearchParameters, - style: StyleType, + style: &Arc, language: Language, ) -> Column<'static, Message> { - let font = get_font(style); + let font = get_font(&style); let search_params2 = search_params.clone(); let mut title_row = Row::new().spacing(10).align_items(Alignment::Center).push( @@ -246,7 +251,7 @@ fn filters_col( if search_params.is_some_filter_active() { title_row = title_row.push(button_clear_filter( SearchParameters::default(), - style, + &style, font, )); } @@ -271,13 +276,13 @@ fn filters_col( .size(18) .font(font) .style(>::into( - StyleTuple(style, ElementType::Badge), + StyleTuple(Arc::clone(style), ElementType::Badge), )), ) .padding([5, 8]) .style(>::into( StyleTuple( - style, + Arc::clone(style), if search_params.only_favorites { ElementType::Badge } else { @@ -297,7 +302,7 @@ fn filters_col( 60.0, search_params.clone(), font, - style, + &style, )) .push(filter_input( FilterInputType::Country, @@ -306,7 +311,7 @@ fn filters_col( 30.0, search_params.clone(), font, - style, + &style, )), ) .push( @@ -320,7 +325,7 @@ fn filters_col( 120.0, search_params.clone(), font, - style, + &style, )) .push(filter_input( FilterInputType::AS, @@ -329,7 +334,7 @@ fn filters_col( 120.0, search_params.clone(), font, - style, + &style, )), ) } @@ -341,7 +346,7 @@ fn filter_input( width: f32, search_params: SearchParameters, font: Font, - style: StyleType, + style: &Arc, ) -> Container<'static, Message> { let is_filter_active = !filter_value.is_empty(); @@ -394,7 +399,7 @@ fn filter_input( .width(Length::Fixed(width)) .style(>::into( StyleTuple( - style, + Arc::clone(style), if is_filter_active { ElementType::Badge } else { @@ -416,7 +421,7 @@ fn filter_input( .padding(5) .style(>::into( StyleTuple( - style, + Arc::clone(style), if is_filter_active { ElementType::Badge } else { @@ -426,7 +431,7 @@ fn filter_input( )) } -fn get_button_change_page(style: StyleType, increment: bool) -> Button<'static, Message> { +fn get_button_change_page(style: &Arc, increment: bool) -> Button<'static, Message> { button( Text::new(if increment { "j" } else { "i" }) .size(10.0) @@ -437,12 +442,12 @@ fn get_button_change_page(style: StyleType, increment: bool) -> Button<'static, .padding(5) .height(Length::Fixed(25.0)) .width(Length::Fixed(25.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::UpdatePageNumber(increment)) } fn get_change_page_row( - style: StyleType, + style: &Arc, language: Language, page_number: usize, start_entry_num: usize, @@ -475,7 +480,7 @@ fn get_change_page_row( } fn get_button_open_report( - style: StyleType, + style: &Arc, language: Language, font: Font, ) -> Tooltip<'static, Message> { @@ -488,20 +493,20 @@ fn get_button_open_report( .padding(10) .height(Length::Fixed(50.0)) .width(Length::Fixed(75.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::OpenReport); Tooltip::new(content, get_open_report_tooltip(language), Position::Top) .gap(5) .font(font) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )) } fn button_clear_filter( new_search_parameters: SearchParameters, - style: StyleType, + style: &Arc, font: Font, ) -> Button<'static, Message> { button( @@ -513,6 +518,6 @@ fn button_clear_filter( .padding(2) .height(Length::Fixed(20.0)) .width(Length::Fixed(20.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::Search(new_search_parameters)) } diff --git a/src/gui/pages/notifications_page.rs b/src/gui/pages/notifications_page.rs index 7bf6d751..7f30e7a6 100644 --- a/src/gui/pages/notifications_page.rs +++ b/src/gui/pages/notifications_page.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use iced::alignment::{Horizontal, Vertical}; use iced::widget::{Column, Container, Row, Scrollable, Text, Tooltip}; use iced::Length::FillPortion; @@ -32,7 +34,7 @@ use crate::{Language, RunningPage, Sniffer, StyleType}; /// Computes the body of gui notifications page pub fn notifications_page(sniffer: &Sniffer) -> Container { let notifications = sniffer.notifications; - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let mut tab_and_body = Column::new() .align_items(Alignment::Center) @@ -51,7 +53,7 @@ pub fn notifications_page(sniffer: &Sniffer) -> Container { Message::TickInit, ], RunningPage::Notifications, - sniffer.style, + &sniffer.style, sniffer.language, sniffer.unread_notifications, ); @@ -65,7 +67,7 @@ pub fn notifications_page(sniffer: &Sniffer) -> Container { && !notifications.favorite_notification.notify_on_favorite && sniffer.runtime_data.logged_notifications.is_empty() { - let body = body_no_notifications_set(sniffer.style, font, sniffer.language); + let body = body_no_notifications_set(&sniffer.style, font, sniffer.language); tab_and_body = tab_and_body.push(body); } else if sniffer.runtime_data.logged_notifications.is_empty() { let body = body_no_notifications_received(font, sniffer.language, &sniffer.waiting); @@ -76,7 +78,7 @@ pub fn notifications_page(sniffer: &Sniffer) -> Container { sniffer.runtime_data.tot_emitted_notifications, sniffer.runtime_data.logged_notifications.len(), sniffer.language, - sniffer.style, + Arc::clone(&sniffer.style), ), move |_| lazy_logged_notifications(sniffer), ); @@ -98,12 +100,12 @@ pub fn notifications_page(sniffer: &Sniffer) -> Container { Scrollable::new(logged_notifications).style(>::into(StyleTuple( - sniffer.style, + Arc::clone(&sniffer.style), ElementType::Standard, ))), ) .push( - Container::new(get_button_clear_all(sniffer.style, sniffer.language)) + Container::new(get_button_clear_all(&sniffer.style, sniffer.language)) .width(Length::FillPortion(1)) .height(Length::Fill) .align_x(Horizontal::Center) @@ -115,12 +117,12 @@ pub fn notifications_page(sniffer: &Sniffer) -> Container { Container::new(Column::new().push(tab_and_body)) .height(Length::Fill) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )) } fn body_no_notifications_set( - style: StyleType, + style: &Arc, font: Font, language: Language, ) -> Column<'static, Message> { @@ -166,7 +168,7 @@ fn body_no_notifications_received( fn packets_notification_log( logged_notification: PacketsThresholdExceeded, language: Language, - style: StyleType, + style: &Arc, ) -> Container<'static, Message> { let font = get_font(style); let threshold_str = format!( @@ -195,7 +197,7 @@ fn packets_notification_log( ) .font(font) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )), ) .push( @@ -229,14 +231,14 @@ fn packets_notification_log( .width(Length::Fixed(800.0)) .padding(10) .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + StyleTuple(Arc::clone(style), ElementType::BorderedRound), )) } fn bytes_notification_log( logged_notification: BytesThresholdExceeded, language: Language, - style: StyleType, + style: &Arc, ) -> Container<'static, Message> { let font = get_font(style); let mut threshold_str = threshold_translation(language); @@ -270,7 +272,7 @@ fn bytes_notification_log( ) .font(font) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )), ) .push( @@ -306,14 +308,14 @@ fn bytes_notification_log( .width(Length::Fixed(800.0)) .padding(10) .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + StyleTuple(Arc::clone(style), ElementType::BorderedRound), )) } fn favorite_notification_log( logged_notification: FavoriteTransmitted, language: Language, - style: StyleType, + style: &Arc, ) -> Container<'static, Message> { let font = get_font(style); let domain = logged_notification.host.domain; @@ -350,7 +352,7 @@ fn favorite_notification_log( ) .font(font) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )), ) .push( @@ -376,11 +378,11 @@ fn favorite_notification_log( .width(Length::Fixed(800.0)) .padding(10) .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + StyleTuple(Arc::clone(style), ElementType::BorderedRound), )) } -fn get_button_clear_all(style: StyleType, language: Language) -> Tooltip<'static, Message> { +fn get_button_clear_all(style: &Arc, language: Language) -> Tooltip<'static, Message> { let content = button( Text::new('h'.to_string()) .font(ICONS) @@ -391,14 +393,14 @@ fn get_button_clear_all(style: StyleType, language: Language) -> Tooltip<'static .padding(10) .height(Length::Fixed(50.0)) .width(Length::Fixed(75.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::ShowModal(MyModal::ClearAll)); Tooltip::new(content, clear_all_translation(language), Position::Top) .gap(5) .font(get_font(style)) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )) } @@ -415,21 +417,21 @@ fn lazy_logged_notifications(sniffer: &Sniffer) -> Column<'static, Message> { packets_notification_log( packet_threshold_exceeded.clone(), sniffer.language, - sniffer.style, + &sniffer.style, ) } LoggedNotification::BytesThresholdExceeded(byte_threshold_exceeded) => { bytes_notification_log( byte_threshold_exceeded.clone(), sniffer.language, - sniffer.style, + &sniffer.style, ) } LoggedNotification::FavoriteTransmitted(favorite_transmitted) => { favorite_notification_log( favorite_transmitted.clone(), sniffer.language, - sniffer.style, + &sniffer.style, ) } }); diff --git a/src/gui/pages/overview_page.rs b/src/gui/pages/overview_page.rs index 385081a8..e0f8bfea 100644 --- a/src/gui/pages/overview_page.rs +++ b/src/gui/pages/overview_page.rs @@ -3,6 +3,8 @@ //! It contains elements to display traffic statistics: chart, detailed connections data //! and overall statistics about the filtered traffic. +use std::sync::Arc; + use iced::alignment::{Horizontal, Vertical}; use iced::widget::{button, vertical_space, Column, Container, Row, Scrollable, Text}; use iced::Length::{Fill, FillPortion}; @@ -41,7 +43,7 @@ use crate::{AppProtocol, ChartType, Language, RunningPage}; /// Computes the body of gui overview page pub fn overview_page(sniffer: &Sniffer) -> Container { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let mut body = Column::new(); let mut tab_and_body = Column::new().height(Length::Fill); @@ -84,7 +86,7 @@ pub fn overview_page(sniffer: &Sniffer) -> Container { Message::ChangeRunningPage(RunningPage::Notifications), ], RunningPage::Overview, - sniffer.style, + &sniffer.style, sniffer.language, sniffer.unread_notifications, ); @@ -120,13 +122,13 @@ pub fn overview_page(sniffer: &Sniffer) -> Container { .align_x(Horizontal::Center) .align_y(Vertical::Center) .style(>::into( - StyleTuple(sniffer.style, ElementType::BorderedRound), + StyleTuple(Arc::clone(&sniffer.style), ElementType::BorderedRound), )); let col_info = lazy( ( total, - sniffer.style, + Arc::clone(&sniffer.style), sniffer.language, sniffer.traffic_chart.chart_type, ), @@ -138,7 +140,7 @@ pub fn overview_page(sniffer: &Sniffer) -> Container { ( filtered, num_favorites, - sniffer.style, + Arc::clone(&sniffer.style), sniffer.language, sniffer.traffic_chart.chart_type, ), @@ -161,7 +163,10 @@ pub fn overview_page(sniffer: &Sniffer) -> Container { .height(Length::Fill) .align_x(Horizontal::Center) .style(>::into( - StyleTuple(sniffer.style, ElementType::BorderedRound), + StyleTuple( + Arc::clone(&sniffer.style), + ElementType::BorderedRound, + ), )), ) .push(col_chart), @@ -186,7 +191,7 @@ pub fn overview_page(sniffer: &Sniffer) -> Container { Container::new(Column::new().push(tab_and_body.push(body))) .height(Length::Fill) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )) } @@ -291,7 +296,7 @@ fn lazy_row_report(sniffer: &Sniffer) -> Row<'static, Message> { .push(col_host) .push( Rule::vertical(40).style(>::into(StyleTuple( - sniffer.style, + Arc::clone(&sniffer.style), ElementType::Standard, ))), ) @@ -302,13 +307,13 @@ fn lazy_row_report(sniffer: &Sniffer) -> Row<'static, Message> { .height(Length::Fill) .width(Length::Fixed(1170.0)) .style(>::into( - StyleTuple(sniffer.style, ElementType::BorderedRound), + StyleTuple(Arc::clone(&sniffer.style), ElementType::BorderedRound), )), ) } fn col_host(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let chart_type = sniffer.traffic_chart.chart_type; let mut col_host = Column::new() @@ -345,7 +350,7 @@ fn col_host(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { .width(Length::Fixed(FLAGS_WIDTH_BIG)) .style( StyleTuple( - sniffer.style, + Arc::clone(&sniffer.style), if data_info_host.is_favorite { ElementType::Starred } else { @@ -400,7 +405,7 @@ fn col_host(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { .push(Rule::horizontal(1).style(>::into( - StyleTuple(sniffer.style, ElementType::Incoming), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Incoming), ))), ) .push( @@ -410,7 +415,7 @@ fn col_host(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { .push(Rule::horizontal(1).style(>::into( - StyleTuple(sniffer.style, ElementType::Outgoing), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Outgoing), ))), ), ); @@ -425,7 +430,7 @@ fn col_host(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { data_info_host.is_local, data_info_host.traffic_type, sniffer.language, - sniffer.style, + &sniffer.style, )) .push(host_bar); @@ -438,7 +443,7 @@ fn col_host(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { as_name: host.asn.name.clone(), ..SearchParameters::default() })) - .style(StyleTuple(sniffer.style, ElementType::Neutral).into()), + .style(StyleTuple(Arc::clone(&sniffer.style), ElementType::Neutral).into()), ); } @@ -454,7 +459,7 @@ fn col_host(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { col_host = col_host.push( Scrollable::new(Container::new(scroll_host).width(Length::Fill)).style( >::into(StyleTuple( - sniffer.style, + Arc::clone(&sniffer.style), ElementType::Standard, )), ), @@ -464,7 +469,7 @@ fn col_host(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { } fn col_app(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let chart_type = sniffer.traffic_chart.chart_type; let mut col_app = Column::new() @@ -527,7 +532,7 @@ fn col_app(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { .push(Rule::horizontal(1).style(>::into( - StyleTuple(sniffer.style, ElementType::Incoming), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Incoming), ))), ) .push( @@ -537,7 +542,7 @@ fn col_app(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { .push(Rule::horizontal(1).style(>::into( - StyleTuple(sniffer.style, ElementType::Outgoing), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Outgoing), ))), ), ); @@ -549,13 +554,13 @@ fn col_app(width: f32, sniffer: &Sniffer) -> Column<'static, Message> { app: format!("{app:?}"), ..SearchParameters::default() })) - .style(StyleTuple(sniffer.style, ElementType::Neutral).into()), + .style(StyleTuple(Arc::clone(&sniffer.style), ElementType::Neutral).into()), ); } col_app = col_app.push( Scrollable::new(Container::new(scroll_app).width(Length::Fill)).style( >::into(StyleTuple( - sniffer.style, + Arc::clone(&sniffer.style), ElementType::Standard, )), ), @@ -570,7 +575,7 @@ fn lazy_col_info( dropped: u32, sniffer: &Sniffer, ) -> Column<'static, Message> { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let filtered_bytes = sniffer.runtime_data.tot_sent_bytes + sniffer.runtime_data.tot_received_bytes; @@ -612,7 +617,7 @@ fn lazy_col_info( .push(chart_radios( sniffer.traffic_chart.chart_type, font, - sniffer.style, + &sniffer.style, sniffer.language, )); @@ -675,14 +680,14 @@ fn lazy_col_info( .push(col_device_filters) .push( Rule::vertical(25).style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )), ) .push(col_data_representation), ) .push( Rule::horizontal(25).style(>::into(StyleTuple( - sniffer.style, + Arc::clone(&sniffer.style), ElementType::Standard, ))), ) @@ -690,7 +695,7 @@ fn lazy_col_info( Scrollable::new(col_bytes_packets) .width(Length::Fill) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )), ) } diff --git a/src/gui/pages/settings_language_page.rs b/src/gui/pages/settings_language_page.rs index f26eb0a1..4b447761 100644 --- a/src/gui/pages/settings_language_page.rs +++ b/src/gui/pages/settings_language_page.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use iced::widget::{Column, Container, Text}; use iced::Length::Fixed; use iced::{Alignment, Length}; @@ -15,17 +17,17 @@ use crate::translations::translations::languages_title_translation; use crate::{Language, Sniffer}; pub fn settings_language_page(sniffer: &Sniffer) -> Container { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let language_active = sniffer.language; let row_language_radio_1 = - language_radios(language_active, &Language::ROW1, font, sniffer.style); + language_radios(language_active, &Language::ROW1, font, &sniffer.style); let row_language_radio_2 = - language_radios(language_active, &Language::ROW2, font, sniffer.style); + language_radios(language_active, &Language::ROW2, font, &sniffer.style); let row_language_radio_3 = - language_radios(language_active, &Language::ROW3, font, sniffer.style); + language_radios(language_active, &Language::ROW3, font, &sniffer.style); let row_language_radio_4 = - language_radios(language_active, &Language::ROW4, font, sniffer.style); + language_radios(language_active, &Language::ROW4, font, &sniffer.style); let col_language_radio_all = Column::new() .spacing(10) .push(row_language_radio_1) @@ -36,7 +38,7 @@ pub fn settings_language_page(sniffer: &Sniffer) -> Container { let mut content = Column::new() .align_items(Alignment::Center) .width(Length::Fill) - .push(settings_header(sniffer.style, sniffer.language)) + .push(settings_header(&sniffer.style, sniffer.language)) .push(get_settings_tabs( [ SettingsPage::Notifications, @@ -50,7 +52,7 @@ pub fn settings_language_page(sniffer: &Sniffer) -> Container { Message::TickInit, ], SettingsPage::Language, - sniffer.style, + &sniffer.style, sniffer.language, )) .push(vertical_space(Fixed(15.0))) @@ -69,7 +71,7 @@ pub fn settings_language_page(sniffer: &Sniffer) -> Container { ) .padding(10.0) .style(>::into( - StyleTuple(sniffer.style, ElementType::Badge), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Badge), )), ); } @@ -78,6 +80,6 @@ pub fn settings_language_page(sniffer: &Sniffer) -> Container { .height(Fixed(400.0)) .width(Fixed(800.0)) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )) } diff --git a/src/gui/pages/settings_notifications_page.rs b/src/gui/pages/settings_notifications_page.rs index 776b06de..b4848990 100644 --- a/src/gui/pages/settings_notifications_page.rs +++ b/src/gui/pages/settings_notifications_page.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use iced::alignment::{Horizontal, Vertical}; use iced::widget::{ button, horizontal_space, vertical_space, Checkbox, Column, Container, Row, Scrollable, Text, @@ -30,10 +32,10 @@ use crate::translations::translations::{ use crate::{Language, Sniffer, StyleType}; pub fn settings_notifications_page(sniffer: &Sniffer) -> Container { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let mut content = Column::new() .width(Length::Fill) - .push(settings_header(sniffer.style, sniffer.language)) + .push(settings_header(&sniffer.style, sniffer.language)) .push(get_settings_tabs( [ SettingsPage::Notifications, @@ -47,7 +49,7 @@ pub fn settings_notifications_page(sniffer: &Sniffer) -> Container { Message::OpenSettings(SettingsPage::Language), ], SettingsPage::Notifications, - sniffer.style, + &sniffer.style, sniffer.language, )) .push(vertical_space(Fixed(15.0))) @@ -65,7 +67,7 @@ pub fn settings_notifications_page(sniffer: &Sniffer) -> Container { .width(Length::Fill) .push(volume_slider( sniffer.language, - sniffer.style, + &sniffer.style, sniffer.notifications.volume, )) .push( @@ -75,21 +77,21 @@ pub fn settings_notifications_page(sniffer: &Sniffer) -> Container { .push(get_packets_notify( sniffer.notifications.packets_notification, sniffer.language, - sniffer.style, + &sniffer.style, )) .push(get_bytes_notify( sniffer.notifications.bytes_notification, sniffer.language, - sniffer.style, + &sniffer.style, )) .push(get_favorite_notify( sniffer.notifications.favorite_notification, sniffer.language, - sniffer.style, + &sniffer.style, )), ) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )), ); @@ -99,14 +101,14 @@ pub fn settings_notifications_page(sniffer: &Sniffer) -> Container { .height(Fixed(400.0)) .width(Fixed(800.0)) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )) } fn get_packets_notify( packets_notification: PacketsNotification, language: Language, - style: StyleType, + style: &Arc, ) -> Column<'static, Message> { let font = get_font(style); let checkbox = Checkbox::new( @@ -135,7 +137,7 @@ fn get_packets_notify( .size(18) .font(font) .style(>::into( - StyleTuple(style, ElementType::Standard), + StyleTuple(Arc::clone(style), ElementType::Standard), )); let mut ret_val = Column::new().spacing(5).push(checkbox); @@ -146,7 +148,7 @@ fn get_packets_notify( .padding(10) .width(Fixed(700.0)) .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + StyleTuple(Arc::clone(style), ElementType::BorderedRound), )), ) } else { @@ -172,7 +174,7 @@ fn get_packets_notify( .padding(10) .width(Fixed(700.0)) .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + StyleTuple(Arc::clone(style), ElementType::BorderedRound), )), ) } @@ -181,7 +183,7 @@ fn get_packets_notify( fn get_bytes_notify( bytes_notification: BytesNotification, language: Language, - style: StyleType, + style: &Arc, ) -> Column<'static, Message> { let font = get_font(style); let checkbox = Checkbox::new( @@ -210,7 +212,7 @@ fn get_bytes_notify( .size(18) .font(font) .style(>::into( - StyleTuple(style, ElementType::Standard), + StyleTuple(Arc::clone(style), ElementType::Standard), )); let mut ret_val = Column::new().spacing(5).push(checkbox); @@ -221,7 +223,7 @@ fn get_bytes_notify( .padding(10) .width(Fixed(700.0)) .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + StyleTuple(Arc::clone(style), ElementType::BorderedRound), )), ) } else { @@ -247,7 +249,7 @@ fn get_bytes_notify( .padding(10) .width(Fixed(700.0)) .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + StyleTuple(Arc::clone(style), ElementType::BorderedRound), )), ) } @@ -256,7 +258,7 @@ fn get_bytes_notify( fn get_favorite_notify( favorite_notification: FavoriteNotification, language: Language, - style: StyleType, + style: &Arc, ) -> Column<'static, Message> { let font = get_font(style); let checkbox = Checkbox::new( @@ -276,7 +278,7 @@ fn get_favorite_notify( .size(18) .font(font) .style(>::into( - StyleTuple(style, ElementType::Standard), + StyleTuple(Arc::clone(style), ElementType::Standard), )); let mut ret_val = Column::new().spacing(5).push(checkbox); @@ -296,7 +298,7 @@ fn get_favorite_notify( .padding(10) .width(Fixed(700.0)) .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + StyleTuple(Arc::clone(style), ElementType::BorderedRound), )), ) } else { @@ -305,7 +307,7 @@ fn get_favorite_notify( .padding(10) .width(Fixed(700.0)) .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + StyleTuple(Arc::clone(style), ElementType::BorderedRound), )), ) } @@ -313,7 +315,7 @@ fn get_favorite_notify( fn input_group_packets( packets_notification: PacketsNotification, - style: StyleType, + style: &Arc, language: Language, ) -> Container<'static, Message> { let font = get_font(style); @@ -341,7 +343,7 @@ fn input_group_packets( .font(font) .width(Length::Fixed(100.0)) .style(>::into( - StyleTuple(style, ElementType::Standard), + StyleTuple(Arc::clone(style), ElementType::Standard), )), ) .push( @@ -357,7 +359,7 @@ fn input_group_packets( fn input_group_bytes( bytes_notification: BytesNotification, - style: StyleType, + style: &Arc, language: Language, ) -> Container<'static, Message> { let font = get_font(style); @@ -386,7 +388,7 @@ fn input_group_bytes( .font(font) .width(Length::Fixed(100.0)) .style(>::into( - StyleTuple(style, ElementType::Standard), + StyleTuple(Arc::clone(style), ElementType::Standard), )), ) .push( @@ -400,7 +402,11 @@ fn input_group_bytes( .align_y(Vertical::Center) } -fn volume_slider(language: Language, style: StyleType, volume: u8) -> Container<'static, Message> { +fn volume_slider( + language: Language, + style: &Arc, + volume: u8, +) -> Container<'static, Message> { let font = get_font(style); Container::new( Column::new() @@ -421,7 +427,7 @@ fn volume_slider(language: Language, style: StyleType, volume: u8) -> Container< .step(5) .width(Fixed(200.0)) .style(>::into(StyleTuple( - style, + Arc::clone(style), ElementType::Standard, ))), ) @@ -441,7 +447,7 @@ fn volume_slider(language: Language, style: StyleType, volume: u8) -> Container< .align_y(Vertical::Center) } -pub fn settings_header(style: StyleType, language: Language) -> Container<'static, Message> { +pub fn settings_header(style: &Arc, language: Language) -> Container<'static, Message> { let font = get_font(style); let tooltip = hide_translation(language).to_string(); //tooltip.push_str(" [esc]"); @@ -467,14 +473,14 @@ pub fn settings_header(style: StyleType, language: Language) -> Container<'stati .padding(2) .height(Fixed(20.0)) .width(Fixed(20.0)) - .style(StyleTuple(style, ElementType::Standard).into()) + .style(StyleTuple(Arc::clone(style), ElementType::Standard).into()) .on_press(Message::CloseSettings), tooltip, Position::Right, ) .font(font) .style(>::into( - StyleTuple(style, ElementType::Tooltip), + StyleTuple(Arc::clone(style), ElementType::Tooltip), )), ) .width(Length::FillPortion(1)) @@ -486,6 +492,6 @@ pub fn settings_header(style: StyleType, language: Language) -> Container<'stati .height(Fixed(40.0)) .width(Length::Fill) .style(>::into( - StyleTuple(style, ElementType::Headers), + StyleTuple(Arc::clone(style), ElementType::Headers), )) } diff --git a/src/gui/pages/settings_style_page.rs b/src/gui/pages/settings_style_page.rs index 9064d8ac..8eccc2ea 100644 --- a/src/gui/pages/settings_style_page.rs +++ b/src/gui/pages/settings_style_page.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use iced::widget::{Button, Column, Container, Row, Text}; use iced::{Alignment, Length}; use iced_native::svg::Handle; @@ -20,11 +22,11 @@ use crate::StyleType::{Day, DeepSea, MonAmour, Night}; use crate::{Sniffer, StyleType}; pub fn settings_style_page(sniffer: &Sniffer) -> Container { - let font = get_font(sniffer.style); + let font = get_font(&sniffer.style); let content = Column::new() .align_items(Alignment::Center) .width(Length::Fill) - .push(settings_header(sniffer.style, sniffer.language)) + .push(settings_header(&sniffer.style, sniffer.language)) .push(get_settings_tabs( [ SettingsPage::Notifications, @@ -38,7 +40,7 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container { Message::OpenSettings(SettingsPage::Language), ], SettingsPage::Appearance, - sniffer.style, + &sniffer.style, sniffer.language, )) .push(vertical_space(Length::Fixed(15.0))) @@ -51,38 +53,38 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container { .push( Row::new() .push(get_palette_container( - sniffer.style, + &sniffer.style, YETI_NIGHT, "Yeti Night".to_string(), yeti_night_translation(sniffer.language).to_string(), - Night, + &Arc::new(Night), )) .push(horizontal_space(Length::Fixed(15.0))) .push(get_palette_container( - sniffer.style, + &sniffer.style, YETI_DAY, "Yeti Day".to_string(), yeti_day_translation(sniffer.language).to_string(), - Day, + &Arc::new(Day), )), ) .push(vertical_space(Length::Fixed(10.0))) .push( Row::new() .push(get_palette_container( - sniffer.style, + &sniffer.style, DEEP_SEA, "Deep Sea".to_string(), deep_sea_translation(sniffer.language).to_string(), - DeepSea, + &Arc::new(DeepSea), )) .push(horizontal_space(Length::Fixed(15.0))) .push(get_palette_container( - sniffer.style, + &sniffer.style, MON_AMOUR, "Mon Amour".to_string(), mon_amour_translation(sniffer.language).to_string(), - MonAmour, + &Arc::new(MonAmour), )), ); @@ -90,16 +92,16 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container { .height(Length::Fixed(400.0)) .width(Length::Fixed(800.0)) .style(>::into( - StyleTuple(sniffer.style, ElementType::Standard), + StyleTuple(Arc::clone(&sniffer.style), ElementType::Standard), )) } fn get_palette_container( - style: StyleType, + style: &Arc, picture: &[u8], name: String, description: String, - on_press: StyleType, + on_press: &Arc, ) -> Button<'static, Message> { let font = get_font(style); let content = Column::new() @@ -116,7 +118,7 @@ fn get_palette_container( .padding(5) .style( StyleTuple( - style, + Arc::clone(style), if on_press.eq(&style) { ElementType::BorderedRoundSelected } else { @@ -125,5 +127,5 @@ fn get_palette_container( ) .into(), ) - .on_press(Message::Style(on_press)) + .on_press(Message::Style(Arc::clone(on_press))) } diff --git a/src/gui/styles/button.rs b/src/gui/styles/button.rs index b3487632..44780b6c 100644 --- a/src/gui/styles/button.rs +++ b/src/gui/styles/button.rs @@ -20,11 +20,11 @@ impl button::StyleSheet for StyleTuple { type Style = iced::Theme; fn active(&self, _: &Self::Style) -> button::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); button::Appearance { background: Some(Background::Color(match self { StyleTuple(_, ElementType::TabActive) => colors.primary, - StyleTuple(_, ElementType::Starred) => get_starred_color(self.0), + StyleTuple(_, ElementType::Starred) => get_starred_color(&self.0), StyleTuple(_, ElementType::Badge) => colors.secondary, StyleTuple(_, ElementType::BorderedRound) => colors.round_containers, StyleTuple(_, ElementType::Neutral | ElementType::NotStarred) => Color::TRANSPARENT, @@ -72,14 +72,14 @@ impl button::StyleSheet for StyleTuple { } fn hovered(&self, _: &Self::Style) -> button::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); button::Appearance { shadow_offset: match self.1 { ElementType::Neutral => Vector::default(), _ => Vector::new(0.0, 2.0), }, background: Some(Background::Color(match self { - StyleTuple(_, ElementType::Starred) => get_starred_color(self.0), + StyleTuple(_, ElementType::Starred) => get_starred_color(&self.0), StyleTuple(_, ElementType::TabActive) => colors.primary, _ => mix_colors(colors.primary, colors.buttons), })), diff --git a/src/gui/styles/checkbox.rs b/src/gui/styles/checkbox.rs index f15a3cc1..a219db2c 100644 --- a/src/gui/styles/checkbox.rs +++ b/src/gui/styles/checkbox.rs @@ -17,7 +17,7 @@ impl iced::widget::checkbox::StyleSheet for StyleTuple { type Style = iced::Theme; fn active(&self, _: &Self::Style, is_checked: bool) -> Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Appearance { background: Background::Color(colors.buttons), icon_color: colors.text_body, @@ -29,7 +29,7 @@ impl iced::widget::checkbox::StyleSheet for StyleTuple { } fn hovered(&self, _: &Self::Style, _is_checked: bool) -> Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Appearance { background: Background::Color(colors.buttons), icon_color: colors.text_body, diff --git a/src/gui/styles/container.rs b/src/gui/styles/container.rs index 036e6394..154e4cb2 100644 --- a/src/gui/styles/container.rs +++ b/src/gui/styles/container.rs @@ -21,7 +21,7 @@ impl iced::widget::container::StyleSheet for StyleTuple { type Style = Theme; fn appearance(&self, _: &Self::Style) -> Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Appearance { text_color: Some(match self { StyleTuple(_, ElementType::Headers) => colors.text_headers, @@ -33,7 +33,7 @@ impl iced::widget::container::StyleSheet for StyleTuple { StyleTuple(_, ElementType::BorderedRound) => colors.round_containers, StyleTuple(_, ElementType::Neutral) => Color::TRANSPARENT, StyleTuple(_, ElementType::Badge) => Color { - a: get_color_mix_filter_badge(self.0), + a: get_color_mix_filter_badge(&self.0), ..colors.secondary }, _ => colors.primary, diff --git a/src/gui/styles/picklist.rs b/src/gui/styles/picklist.rs index b1de8f7b..455bcdf9 100644 --- a/src/gui/styles/picklist.rs +++ b/src/gui/styles/picklist.rs @@ -19,7 +19,7 @@ impl iced::overlay::menu::StyleSheet for StyleTuple { type Style = iced::Theme; fn appearance(&self, _: &Self::Style) -> iced::overlay::menu::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); iced::overlay::menu::Appearance { text_color: colors.text_body, background: Background::Color(colors.buttons), @@ -36,7 +36,7 @@ impl pick_list::StyleSheet for StyleTuple { type Style = iced::Theme; fn active(&self, _: &Self::Style) -> pick_list::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); pick_list::Appearance { text_color: colors.text_body, placeholder_color: colors.text_body, @@ -49,7 +49,7 @@ impl pick_list::StyleSheet for StyleTuple { } fn hovered(&self, _: &Self::Style) -> pick_list::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); pick_list::Appearance { text_color: colors.text_body, placeholder_color: colors.text_body, diff --git a/src/gui/styles/radio.rs b/src/gui/styles/radio.rs index 09862665..7bc072cd 100644 --- a/src/gui/styles/radio.rs +++ b/src/gui/styles/radio.rs @@ -17,7 +17,7 @@ impl iced::widget::radio::StyleSheet for StyleTuple { type Style = Theme; fn active(&self, _: &Self::Style, is_selected: bool) -> iced::widget::radio::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); iced::widget::radio::Appearance { background: Background::Color(colors.buttons), dot_color: colors.secondary, @@ -28,7 +28,7 @@ impl iced::widget::radio::StyleSheet for StyleTuple { } fn hovered(&self, _: &Self::Style, _is_selected: bool) -> iced::widget::radio::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); iced::widget::radio::Appearance { background: Background::Color(colors.buttons), dot_color: colors.secondary, diff --git a/src/gui/styles/rule.rs b/src/gui/styles/rule.rs index a17e8954..1b07fd6e 100644 --- a/src/gui/styles/rule.rs +++ b/src/gui/styles/rule.rs @@ -17,7 +17,7 @@ impl rule::StyleSheet for StyleTuple { type Style = iced::Theme; fn appearance(&self, _: &Self::Style) -> iced::widget::rule::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); iced::widget::rule::Appearance { color: match self.1 { ElementType::Incoming => colors.secondary, diff --git a/src/gui/styles/scrollbar.rs b/src/gui/styles/scrollbar.rs index 58605df0..fda6d931 100644 --- a/src/gui/styles/scrollbar.rs +++ b/src/gui/styles/scrollbar.rs @@ -18,7 +18,7 @@ impl iced::widget::scrollable::StyleSheet for StyleTuple { type Style = Theme; fn active(&self, _: &Self::Style) -> Scrollbar { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Scrollbar { background: Some(Background::Color(colors.round_borders)), border_radius: BORDER_ROUNDED_RADIUS, @@ -34,7 +34,7 @@ impl iced::widget::scrollable::StyleSheet for StyleTuple { } fn hovered(&self, _: &Self::Style, is_mouse_over_scrollbar: bool) -> Scrollbar { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Scrollbar { background: Some(Background::Color(colors.round_borders)), border_radius: BORDER_ROUNDED_RADIUS, diff --git a/src/gui/styles/slider.rs b/src/gui/styles/slider.rs index 5bffcf80..51dc33d9 100644 --- a/src/gui/styles/slider.rs +++ b/src/gui/styles/slider.rs @@ -19,7 +19,7 @@ impl iced::widget::slider::StyleSheet for StyleTuple { type Style = iced::Theme; fn active(&self, _: &Self::Style) -> Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Appearance { rail: Rail { colors: (colors.secondary, colors.buttons), @@ -35,7 +35,7 @@ impl iced::widget::slider::StyleSheet for StyleTuple { } fn hovered(&self, _: &Self::Style) -> Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Appearance { rail: Rail { colors: (colors.secondary, colors.buttons), @@ -51,7 +51,7 @@ impl iced::widget::slider::StyleSheet for StyleTuple { } fn dragging(&self, _: &Self::Style) -> Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Appearance { rail: Rail { colors: (colors.secondary, colors.buttons), diff --git a/src/gui/styles/style_constants.rs b/src/gui/styles/style_constants.rs index d4c1a922..373b5407 100644 --- a/src/gui/styles/style_constants.rs +++ b/src/gui/styles/style_constants.rs @@ -166,24 +166,25 @@ pub const SARASA_MONO_SC_BOLD: Font = Font::External { bytes: include_bytes!("../../../resources/fonts/subset/sarasa-mono-sc-bold.subset.ttf"), }; -pub fn get_font(style: StyleType) -> Font { +pub fn get_font(style: &StyleType) -> Font { match to_rgb_color(get_colors(style).text_body) { RGBColor(255, 255, 255) => Font::Default, _ => SARASA_MONO_SC_BOLD, } } -pub fn get_font_headers(style: StyleType) -> Font { +pub fn get_font_headers(style: &StyleType) -> Font { match to_rgb_color(get_colors(style).text_headers) { RGBColor(255, 255, 255) => Font::Default, _ => SARASA_MONO_SC_BOLD, } } -pub fn get_color_mix_chart(style: StyleType) -> f64 { +pub fn get_color_mix_chart(style: &StyleType) -> f64 { match style { StyleType::Night | StyleType::DeepSea => 0.3, StyleType::Day | StyleType::MonAmour => 0.8, + StyleType::Custom(style) => style.palette.extension.color_mix_chart, } } @@ -212,7 +213,7 @@ pub const BORDER_ROUNDED_RADIUS: f32 = 15.0; pub const BORDER_BUTTON_RADIUS: f32 = 180.0; /// Yellow color used in favorites star -pub fn get_starred_color(style: StyleType) -> Color { +pub fn get_starred_color(style: &StyleType) -> Color { match style { StyleType::Night | StyleType::DeepSea => Color { r: 245.0 / 255.0, @@ -226,13 +227,15 @@ pub fn get_starred_color(style: StyleType) -> Color { b: 39.0 / 255.0, a: 0.8, }, + StyleType::Custom(style) => style.palette.extension.starred, } } -pub fn get_color_mix_filter_badge(style: StyleType) -> f32 { +pub fn get_color_mix_filter_badge(style: &StyleType) -> f32 { match style { StyleType::Night | StyleType::DeepSea => 0.2, StyleType::Day => 0.7, StyleType::MonAmour => 0.5, + StyleType::Custom(style) => style.palette.extension.badge_alpha, } } diff --git a/src/gui/styles/text_input.rs b/src/gui/styles/text_input.rs index 5aa5f843..c604b907 100644 --- a/src/gui/styles/text_input.rs +++ b/src/gui/styles/text_input.rs @@ -18,7 +18,7 @@ impl iced::widget::text_input::StyleSheet for StyleTuple { type Style = iced::Theme; fn active(&self, _: &Self::Style) -> iced::widget::text_input::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Appearance { background: Background::Color(match self.1 { ElementType::Badge => Color::TRANSPARENT, @@ -35,7 +35,7 @@ impl iced::widget::text_input::StyleSheet for StyleTuple { } fn focused(&self, _: &Self::Style) -> iced::widget::text_input::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Appearance { background: Background::Color(colors.primary), border_radius: 0.0, @@ -46,7 +46,7 @@ impl iced::widget::text_input::StyleSheet for StyleTuple { } fn placeholder_color(&self, _: &Self::Style) -> Color { - let color = get_colors(self.0).text_body; + let color = get_colors(&self.0).text_body; Color { a: if color.eq(&Color::BLACK) { 0.7 } else { 0.2 }, ..color @@ -54,7 +54,7 @@ impl iced::widget::text_input::StyleSheet for StyleTuple { } fn value_color(&self, _: &Self::Style) -> Color { - get_colors(self.0).text_body + get_colors(&self.0).text_body } fn disabled_color(&self, _style: &Self::Style) -> Color { @@ -62,7 +62,7 @@ impl iced::widget::text_input::StyleSheet for StyleTuple { } fn selection_color(&self, _: &Self::Style) -> Color { - let color = get_colors(self.0).text_body; + let color = get_colors(&self.0).text_body; Color { a: if color.eq(&Color::BLACK) { 0.4 } else { 0.05 }, ..color @@ -70,7 +70,7 @@ impl iced::widget::text_input::StyleSheet for StyleTuple { } fn hovered(&self, _: &Self::Style) -> iced::widget::text_input::Appearance { - let colors = get_colors(self.0); + let colors = get_colors(&self.0); Appearance { background: Background::Color(match self.1 { ElementType::Badge => Color::TRANSPARENT, diff --git a/src/gui/styles/types/custom_style.rs b/src/gui/styles/types/custom_style.rs index 2cb8e92c..c1d3cd60 100644 --- a/src/gui/styles/types/custom_style.rs +++ b/src/gui/styles/types/custom_style.rs @@ -72,6 +72,7 @@ impl PartialEq for CustomPalette { let PaletteExtension { starred, badge_alpha, + color_mix_chart, } = self.extension; // Other @@ -90,6 +91,7 @@ impl PartialEq for CustomPalette { let PaletteExtension { starred: starred_other, badge_alpha: badge_alpha_other, + color_mix_chart: color_mix_chart_other, } = other.extension; color_partialeq(primary, primary_other) @@ -103,6 +105,7 @@ impl PartialEq for CustomPalette { && color_partialeq(round_containers, round_containers_other) && color_partialeq(starred, starred_other) && badge_alpha == badge_alpha_other + && color_mix_chart == color_mix_chart_other } } @@ -254,6 +257,7 @@ mod tests { a: 1.0, }, badge_alpha: 0.75, + color_mix_chart: 0.3, }, }, }) diff --git a/src/gui/styles/types/palette.rs b/src/gui/styles/types/palette.rs index 0fd076a9..a271aaee 100644 --- a/src/gui/styles/types/palette.rs +++ b/src/gui/styles/types/palette.rs @@ -78,12 +78,13 @@ pub struct Palette { pub round_containers: Color, } -pub fn get_colors(style: StyleType) -> Palette { +pub fn get_colors(style: &StyleType) -> &Palette { match style { - StyleType::Night => NIGHT_STYLE, - StyleType::Day => DAY_STYLE, - StyleType::DeepSea => DEEP_SEA_STYLE, - StyleType::MonAmour => MON_AMOUR_STYLE, + StyleType::Night => &NIGHT_STYLE, + StyleType::Day => &DAY_STYLE, + StyleType::DeepSea => &DEEP_SEA_STYLE, + StyleType::MonAmour => &MON_AMOUR_STYLE, + StyleType::Custom(style) => &style.palette.base, } } @@ -119,7 +120,7 @@ pub fn mix_colors(color_1: Color, color_2: Color) -> Color { impl Default for Palette { fn default() -> Self { - get_colors(StyleType::Night) + get_colors(&StyleType::Night).clone() } } @@ -163,6 +164,8 @@ pub struct PaletteExtension { pub starred: Color, /// Badge alpha channel pub badge_alpha: f32, + /// Color mixing for charts + pub color_mix_chart: f64, } impl Hash for PaletteExtension { @@ -171,5 +174,7 @@ impl Hash for PaletteExtension { // f32::NAN is 0i32 when casted using `as`. let alpha: i32 = (self.badge_alpha * 1000.0).trunc() as i32; alpha.hash(state); + let color_mix: i32 = (self.color_mix_chart * 1000.0).trunc() as i32; + color_mix.hash(state) } } diff --git a/src/gui/styles/types/style_tuple.rs b/src/gui/styles/types/style_tuple.rs index 9b146266..3f494b78 100644 --- a/src/gui/styles/types/style_tuple.rs +++ b/src/gui/styles/types/style_tuple.rs @@ -1,11 +1,13 @@ +use std::sync::Arc; + use crate::gui::styles::types::element_type::ElementType; use crate::StyleType; /// This tuple permits to specify the correct style depending on the style type and on the element type -pub struct StyleTuple(pub StyleType, pub ElementType); +pub struct StyleTuple(pub Arc, pub ElementType); impl Clone for StyleTuple { fn clone(&self) -> Self { - Self(self.0, self.1) + Self(Arc::clone(&self.0), self.1) } } diff --git a/src/gui/styles/types/style_type.rs b/src/gui/styles/types/style_type.rs index 98da17bf..c94d9621 100644 --- a/src/gui/styles/types/style_type.rs +++ b/src/gui/styles/types/style_type.rs @@ -1,15 +1,19 @@ use serde::{Deserialize, Serialize}; -use super::custom_style::CustomStyle; +use super::custom_style::{deserialize_from_path, serialize_to_path, CustomStyle}; /// Used to specify the kind of style of the application -#[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] +#[derive(Clone, Serialize, Deserialize, Debug, Hash, PartialEq)] pub enum StyleType { Night, Day, DeepSea, MonAmour, - // Custom(CustomStyle) + #[serde( + serialize_with = "serialize_to_path", + deserialize_with = "deserialize_from_path" + )] + Custom(CustomStyle), } impl Default for StyleType { diff --git a/src/gui/types/message.rs b/src/gui/types/message.rs index 229fed37..2ffea05e 100644 --- a/src/gui/types/message.rs +++ b/src/gui/types/message.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use crate::gui::components::types::my_modal::MyModal; use crate::gui::pages::types::running_page::RunningPage; use crate::gui::pages::types::settings_page::SettingsPage; @@ -39,7 +41,7 @@ pub enum Message { /// Stop sniffing process and return to initial page Reset, /// Change application style - Style(StyleType), + Style(Arc), /// Manage waiting time Waiting, /// Displays a modal diff --git a/src/gui/types/sniffer.rs b/src/gui/types/sniffer.rs index f5365b1a..6fdbfaeb 100644 --- a/src/gui/types/sniffer.rs +++ b/src/gui/types/sniffer.rs @@ -54,7 +54,7 @@ pub struct Sniffer { /// Signals if a pcap error occurred pub pcap_error: Option, /// Application style (only values Day and Night are possible for this field) - pub style: StyleType, + pub style: Arc, /// Waiting string pub waiting: String, /// Chart displayed @@ -102,9 +102,9 @@ impl Sniffer { last_device_name_sniffed: config_device.device_name.clone(), filters: Filters::default(), pcap_error: None, - style: config_settings.style, + style: Arc::clone(&config_settings.style), waiting: ".".to_string(), - traffic_chart: TrafficChart::new(config_settings.style, config_settings.language), + traffic_chart: TrafficChart::new(&config_settings.style, config_settings.language), report_sort_type: ReportSortType::MostRecent, modal: None, settings_page: None, @@ -139,7 +139,7 @@ impl Sniffer { Message::Reset => return self.reset(), Message::Style(style) => { self.style = style; - self.traffic_chart.change_colors(self.style); + self.traffic_chart.change_colors(&self.style); } Message::Waiting => self.update_waiting_dots(), Message::AddOrRemoveFavorite(host, add) => self.add_or_remove_favorite(&host, add), @@ -315,7 +315,7 @@ impl Sniffer { let info_traffic_mutex = self.info_traffic.clone(); *info_traffic_mutex.lock().unwrap() = InfoTraffic::new(); self.runtime_data = RunTimeData::new(); - self.traffic_chart = TrafficChart::new(self.style, self.language); + self.traffic_chart = TrafficChart::new(&self.style, self.language); if pcap_error.is_none() { // no pcap error @@ -390,7 +390,7 @@ impl Sniffer { self.last_opened_setting = self.settings_page.unwrap(); self.settings_page = None; let store = ConfigSettings { - style: self.style, + style: Arc::clone(&self.style), notifications: self.notifications, language: self.language, }; @@ -643,95 +643,95 @@ mod tests { Arc::new(Mutex::new(Err(String::new()))), ); - sniffer.update(Message::Style(StyleType::MonAmour)); - assert_eq!(sniffer.style, StyleType::MonAmour); + sniffer.update(Message::Style(Arc::new(StyleType::MonAmour))); + assert_eq!(*sniffer.style, StyleType::MonAmour); assert_eq!( sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::MonAmour).text_body) + to_rgb_color(get_colors(&StyleType::MonAmour).text_body) ); assert_eq!( sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::MonAmour).outgoing) + to_rgb_color(get_colors(&StyleType::MonAmour).outgoing) ); assert_eq!( sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::MonAmour).secondary) + to_rgb_color(get_colors(&StyleType::MonAmour).secondary) ); assert_eq!( sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::MonAmour) + get_color_mix_chart(&StyleType::MonAmour) ); - sniffer.update(Message::Style(StyleType::Day)); - assert_eq!(sniffer.style, StyleType::Day); + sniffer.update(Message::Style(Arc::new(StyleType::Day))); + assert_eq!(*sniffer.style, StyleType::Day); assert_eq!( sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::Day).text_body) + to_rgb_color(get_colors(&StyleType::Day).text_body) ); assert_eq!( sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::Day).outgoing) + to_rgb_color(get_colors(&StyleType::Day).outgoing) ); assert_eq!( sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::Day).secondary) + to_rgb_color(get_colors(&StyleType::Day).secondary) ); assert_eq!( sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::Day) + get_color_mix_chart(&StyleType::Day) ); - sniffer.update(Message::Style(StyleType::Night)); - assert_eq!(sniffer.style, StyleType::Night); + sniffer.update(Message::Style(Arc::new(StyleType::Night))); + assert_eq!(*sniffer.style, StyleType::Night); assert_eq!( sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::Night).text_body) + to_rgb_color(get_colors(&StyleType::Night).text_body) ); assert_eq!( sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::Night).outgoing) + to_rgb_color(get_colors(&StyleType::Night).outgoing) ); assert_eq!( sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::Night).secondary) + to_rgb_color(get_colors(&StyleType::Night).secondary) ); assert_eq!( sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::Night) + get_color_mix_chart(&StyleType::Night) ); - sniffer.update(Message::Style(StyleType::DeepSea)); - assert_eq!(sniffer.style, StyleType::DeepSea); + sniffer.update(Message::Style(Arc::new(StyleType::DeepSea))); + assert_eq!(*sniffer.style, StyleType::DeepSea); assert_eq!( sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::DeepSea).text_body) + to_rgb_color(get_colors(&StyleType::DeepSea).text_body) ); assert_eq!( sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::DeepSea).outgoing) + to_rgb_color(get_colors(&StyleType::DeepSea).outgoing) ); assert_eq!( sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::DeepSea).secondary) + to_rgb_color(get_colors(&StyleType::DeepSea).secondary) ); assert_eq!( sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::DeepSea) + get_color_mix_chart(&StyleType::DeepSea) ); - sniffer.update(Message::Style(StyleType::DeepSea)); - assert_eq!(sniffer.style, StyleType::DeepSea); + sniffer.update(Message::Style(Arc::new(StyleType::DeepSea))); + assert_eq!(*sniffer.style, StyleType::DeepSea); assert_eq!( sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::DeepSea).text_body) + to_rgb_color(get_colors(&StyleType::DeepSea).text_body) ); assert_eq!( sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::DeepSea).outgoing) + to_rgb_color(get_colors(&StyleType::DeepSea).outgoing) ); assert_eq!( sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::DeepSea).secondary) + to_rgb_color(get_colors(&StyleType::DeepSea).secondary) ); assert_eq!( sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::DeepSea) + get_color_mix_chart(&StyleType::DeepSea) ); } diff --git a/src/report/get_report_entries.rs b/src/report/get_report_entries.rs index 51a7f689..d75927f1 100644 --- a/src/report/get_report_entries.rs +++ b/src/report/get_report_entries.rs @@ -142,7 +142,7 @@ pub fn get_searched_entries( host_info.is_local, host_info.traffic_type, sniffer.language, - sniffer.style, + &sniffer.style, ); (key_val.0.clone(), key_val.1.clone(), flag) }) diff --git a/src/utils/formatted_strings.rs b/src/utils/formatted_strings.rs index 7ac575c5..d3167abc 100644 --- a/src/utils/formatted_strings.rs +++ b/src/utils/formatted_strings.rs @@ -56,11 +56,11 @@ pub fn get_active_filters_string(filters: &Filters, language: Language) -> Strin } /// Returns the color to be used for a specific connection of the relevant connections table in gui run page -pub fn get_connection_color(traffic_direction: TrafficDirection, style: StyleType) -> Color { +pub fn get_connection_color(traffic_direction: TrafficDirection, style: &StyleType) -> Color { if traffic_direction == TrafficDirection::Outgoing { - get_colors(style).outgoing + get_colors(&style).outgoing } else { - get_colors(style).incoming + get_colors(&style).incoming } }