From 9fb0f71804d026ce4250ccb07b5063db75e9a68c Mon Sep 17 00:00:00 2001 From: GyulyVGC Date: Fri, 3 Feb 2023 23:15:56 +0100 Subject: [PATCH] minor changes --- .design/README.md | 2 +- README.md | 2 +- src/enums/language.rs | 2 +- src/enums/sound.rs | 8 +- src/enums/style_type.rs | 2 +- src/gui/components/footer.rs | 2 +- src/gui/components/header.rs | 6 +- src/gui/pages/initial_page.rs | 4 +- src/gui/pages/overview_page.rs | 12 +-- src/gui/pages/settings.rs | 164 ++++++++++++++++-------------- src/gui/styles/button.rs | 2 +- src/gui/styles/container.rs | 4 +- src/gui/styles/slider.rs | 6 +- src/structs/notifications.rs | 2 +- src/utility/manage_charts_data.rs | 4 +- src/utility/manage_packets.rs | 6 +- src/utility/manage_report_data.rs | 2 +- 17 files changed, 119 insertions(+), 111 deletions(-) diff --git a/.design/README.md b/.design/README.md index eed1e933..1100ba8a 100644 --- a/.design/README.md +++ b/.design/README.md @@ -50,7 +50,7 @@ ### Target audience ### Design files -> Since I do not have a design team at hand – most of my product does not have any Design files and you'll be forced to browse through the product itself and propose improvements. +> Since I do not have a design team at hand – most of my product does not have any Design files, and you'll be forced to browse through the product itself and propose improvements. ## 💅 Design relevant materials diff --git a/README.md b/README.md index f447e7c5..15c84cfd 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ ## Installation from GitHub releases  You can install Sniffnet through the installers available in the [latest release](https://github.com/GyulyVGC/sniffnet/releases).
- Choose between a Windows installer, a DEB package, or a MacOS disk image (depending on your operating system). + Choose between a Windows installer, a DEB package, or a macOS disk image (depending on your operating system). diff --git a/src/enums/language.rs b/src/enums/language.rs index f620f8bd..d7b5c7e1 100644 --- a/src/enums/language.rs +++ b/src/enums/language.rs @@ -9,7 +9,7 @@ pub enum Language { IT, } -impl ::std::default::Default for Language { +impl Default for Language { fn default() -> Self { Self::EN } diff --git a/src/enums/sound.rs b/src/enums/sound.rs index 7fdb03be..b258f068 100644 --- a/src/enums/sound.rs +++ b/src/enums/sound.rs @@ -40,16 +40,16 @@ fn mp3_sound(self) -> &'static [u8] { pub fn get_radio_label(&self, language: Language) -> &str { match self { - Sound::Bubble => "Bubble", - Sound::Pop => "Pop", - Sound::Tic => "Tic", + Bubble => "Bubble", + Pop => "Pop", + Tic => "Tic", Sound::None => none_translation(language), } } } pub fn play_sound(sound: Sound, volume: u8) { - if sound.eq(&Sound::None) { + if sound.eq(&Sound::None) || volume == 0 { return; } let mp3_sound = sound.mp3_sound(); diff --git a/src/enums/style_type.rs b/src/enums/style_type.rs index cb5bacea..f6f0dfbe 100644 --- a/src/enums/style_type.rs +++ b/src/enums/style_type.rs @@ -9,7 +9,7 @@ pub enum StyleType { MonAmour, } -impl ::std::default::Default for StyleType { +impl Default for StyleType { fn default() -> Self { Self::Night } diff --git a/src/gui/components/footer.rs b/src/gui/components/footer.rs index 0a9052bf..1029edd4 100644 --- a/src/gui/components/footer.rs +++ b/src/gui/components/footer.rs @@ -38,7 +38,7 @@ pub fn get_footer(style: StyleType) -> Container<'static, Message> { )) } -pub fn get_button_github(style: StyleType) -> iced::widget::Tooltip<'static, Message> { +pub fn get_button_github(style: StyleType) -> Tooltip<'static, Message> { let content = button( Text::new('H'.to_string()) .font(ICONS) diff --git a/src/gui/components/header.rs b/src/gui/components/header.rs index 970cfa21..355eda4f 100644 --- a/src/gui/components/header.rs +++ b/src/gui/components/header.rs @@ -10,7 +10,7 @@ use iced::alignment::{Horizontal, Vertical}; use iced::widget::{button, horizontal_space, Container, Row, Text, Tooltip}; use iced::Length::FillPortion; -use iced::{alignment, Alignment, Length}; +use iced::{Alignment, Length}; use iced_native::widget::tooltip::Position; pub fn get_header( @@ -102,8 +102,8 @@ pub fn get_button_settings(style: StyleType, language: Language) -> Tooltip<'sta let content = button( Text::new("a") .font(ICONS) - .horizontal_alignment(alignment::Horizontal::Center) - .vertical_alignment(alignment::Vertical::Center), + .horizontal_alignment(Horizontal::Center) + .vertical_alignment(Vertical::Center), ) .padding(10) .height(Length::Units(40)) diff --git a/src/gui/pages/initial_page.rs b/src/gui/pages/initial_page.rs index 8ea65286..67119fd1 100644 --- a/src/gui/pages/initial_page.rs +++ b/src/gui/pages/initial_page.rs @@ -46,9 +46,9 @@ pub fn initial_page(sniffer: &Sniffer) -> Container { .spacing(10) .width(FillPortion(2)) .push(col_transport_radio) - .push(vertical_space(Length::FillPortion(2))) + .push(vertical_space(FillPortion(2))) .push(get_button_start(sniffer.style, sniffer.language)) - .push(vertical_space(Length::FillPortion(1))); + .push(vertical_space(FillPortion(1))); let app_active = sniffer.filters.application; let picklist_app = PickList::new( diff --git a/src/gui/pages/overview_page.rs b/src/gui/pages/overview_page.rs index e7dbace9..c458e777 100644 --- a/src/gui/pages/overview_page.rs +++ b/src/gui/pages/overview_page.rs @@ -94,12 +94,12 @@ pub fn overview_page(sniffer: &Sniffer) -> Container { ) }; body = body - .push(vertical_space(Length::FillPortion(1))) + .push(vertical_space(FillPortion(1))) .push(icon_text) .push(vertical_space(Length::Units(15))) .push(nothing_to_see_text) .push(Text::new(sniffer.waiting.clone()).font(font).size(50)) - .push(vertical_space(Length::FillPortion(2))); + .push(vertical_space(FillPortion(2))); } (observed, 0) => { @@ -114,12 +114,12 @@ pub fn overview_page(sniffer: &Sniffer) -> Container { .font(font); body = body - .push(vertical_space(Length::FillPortion(1))) + .push(vertical_space(FillPortion(1))) .push(Text::new('V'.to_string()).font(ICONS).size(60)) .push(vertical_space(Length::Units(15))) .push(tot_packets_text) .push(Text::new(sniffer.waiting.clone()).font(font).size(50)) - .push(vertical_space(Length::FillPortion(2))); + .push(vertical_space(FillPortion(2))); } (observed, filtered) => { @@ -319,12 +319,12 @@ pub fn overview_page(sniffer: &Sniffer) -> Container { .font(font); body = body - .push(vertical_space(Length::FillPortion(1))) + .push(vertical_space(FillPortion(1))) .push(Text::new('U'.to_string()).font(ICONS).size(60)) .push(vertical_space(Length::Units(15))) .push(error_text) .push(Text::new(sniffer.waiting.clone()).font(font).size(50)) - .push(vertical_space(Length::FillPortion(2))); + .push(vertical_space(FillPortion(2))); } Container::new(Column::new().push(tab_and_body.push(body))) diff --git a/src/gui/pages/settings.rs b/src/gui/pages/settings.rs index 88a116ac..2621029c 100644 --- a/src/gui/pages/settings.rs +++ b/src/gui/pages/settings.rs @@ -9,8 +9,8 @@ use crate::structs::style_tuple::StyleTuple; use crate::utility::get_formatted_strings::get_formatted_bytes_string; use crate::utility::style_constants::{ - get_font, get_font_headers, DEEP_SEA, FONT_SIZE_SUBTITLE, FONT_SIZE_TITLE, MON_AMOUR, YETI_DAY, - YETI_NIGHT, + get_font, get_font_headers, DEEP_SEA, FONT_SIZE_SUBTITLE, FONT_SIZE_TITLE, ICONS, MON_AMOUR, + YETI_DAY, YETI_NIGHT, }; use crate::utility::translations::{ appearance_title_translation, bytes_threshold_translation, deep_sea_translation, @@ -26,6 +26,7 @@ button, horizontal_space, image::Handle, vertical_space, Button, Checkbox, Column, Container, Image, Row, Scrollable, Text, Tooltip, }; +use iced::Length::Units; use iced::{Alignment, Length}; use iced_native::widget::tooltip::Position; use iced_native::widget::{Slider, VerticalSlider}; @@ -53,7 +54,7 @@ pub fn settings_notifications_page(sniffer: &Sniffer) -> Container { sniffer.style, sniffer.language, )) - .push(vertical_space(Length::Units(15))) + .push(vertical_space(Units(15))) .push( notifications_title_translation(sniffer.language) .font(font) @@ -61,14 +62,14 @@ pub fn settings_notifications_page(sniffer: &Sniffer) -> Container { .width(Length::Fill) .horizontal_alignment(Horizontal::Center), ) - .push(vertical_space(Length::Units(5))); + .push(vertical_space(Units(5))); let notification_volume_row = Row::new() .width(Length::Fill) .push( Scrollable::new( Column::new() - .width(Length::Units(670)) + .width(Units(670)) .push(get_threshold_notify( sniffer.notifications.packets_notification, sniffer.language, @@ -117,8 +118,8 @@ pub fn settings_notifications_page(sniffer: &Sniffer) -> Container { content = content.push(notification_volume_row); Container::new(content) - .height(Length::Units(400)) - .width(Length::Units(800)) + .height(Units(400)) + .width(Units(800)) .style(>::into( StyleTuple(sniffer.style, ElementType::Standard), )) @@ -146,13 +147,13 @@ pub fn settings_appearance_page(sniffer: &Sniffer) -> Container { sniffer.style, sniffer.language, )) - .push(vertical_space(Length::Units(15))) + .push(vertical_space(Units(15))) .push( appearance_title_translation(sniffer.language) .font(font) .size(FONT_SIZE_SUBTITLE), ) - .push(vertical_space(Length::Units(10))) + .push(vertical_space(Units(10))) .push( Row::new() .push(get_palette_container( @@ -162,7 +163,7 @@ pub fn settings_appearance_page(sniffer: &Sniffer) -> Container { yeti_night_translation(sniffer.language).to_string(), Night, )) - .push(horizontal_space(Length::Units(33))) + .push(horizontal_space(Units(33))) .push(get_palette_container( sniffer.style, YETI_DAY, @@ -171,7 +172,7 @@ pub fn settings_appearance_page(sniffer: &Sniffer) -> Container { Day, )), ) - .push(vertical_space(Length::Units(10))) + .push(vertical_space(Units(10))) .push( Row::new() .push(get_palette_container( @@ -181,7 +182,7 @@ pub fn settings_appearance_page(sniffer: &Sniffer) -> Container { deep_sea_translation(sniffer.language).to_string(), DeepSea, )) - .push(horizontal_space(Length::Units(33))) + .push(horizontal_space(Units(33))) .push(get_palette_container( sniffer.style, MON_AMOUR, @@ -192,8 +193,8 @@ pub fn settings_appearance_page(sniffer: &Sniffer) -> Container { ); Container::new(content) - .height(Length::Units(400)) - .width(Length::Units(800)) + .height(Units(400)) + .width(Units(800)) .style(>::into( StyleTuple(sniffer.style, ElementType::Standard), )) @@ -225,18 +226,18 @@ pub fn settings_language_page(sniffer: &Sniffer) -> Container { sniffer.style, sniffer.language, )) - .push(vertical_space(Length::Units(15))) + .push(vertical_space(Units(15))) .push( languages_title_translation(sniffer.language) .font(font) .size(FONT_SIZE_SUBTITLE), ) - .push(vertical_space(Length::Units(20))) + .push(vertical_space(Units(20))) .push(col_language_radio); Container::new(content) - .height(Length::Units(400)) - .width(Length::Units(800)) + .height(Units(400)) + .width(Units(800)) .style(>::into( StyleTuple(sniffer.style, ElementType::Standard), )) @@ -283,22 +284,22 @@ fn get_threshold_notify( let mut ret_val = Column::new().spacing(5).push(checkbox); if threshold_notification.threshold.is_none() { - Column::new().padding(5).push( - Container::new(ret_val) - .padding(10) - .width(Length::Units(650)) - .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + Column::new() + .padding(5) + .push(Container::new(ret_val).padding(10).width(Units(650)).style( + >::into(StyleTuple( + style, + ElementType::BorderedRound, )), - ) + )) } else { let slider_row = Row::new() - .push(horizontal_space(Length::Units(50))) + .push(horizontal_space(Units(50))) .push( Text::new(threshold_translation(language, &threshold_label.unwrap())) .font(get_font(style)), ) - .push(horizontal_space(Length::Units(30))) + .push(horizontal_space(Units(30))) .push( Slider::new( 0..=upper_bound, @@ -315,34 +316,33 @@ fn get_threshold_notify( }, ) .step(10) - .width(Length::Units(400)) + .width(Units(400)) .style(>::into(StyleTuple( style, ElementType::Standard, ))), ); - let sound_row = - Row::new() - .push(horizontal_space(Length::Units(50))) - .push(sound_threshold_radios( - threshold_notification, - get_font(style), - style, - language, - message, - )); + let sound_row = Row::new() + .push(horizontal_space(Units(50))) + .push(sound_threshold_radios( + threshold_notification, + get_font(style), + style, + language, + message, + )); ret_val = ret_val - .push(vertical_space(Length::Units(5))) + .push(vertical_space(Units(5))) .push(slider_row) .push(sound_row); - Column::new().padding(5).push( - Container::new(ret_val) - .padding(10) - .width(Length::Units(650)) - .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + Column::new() + .padding(5) + .push(Container::new(ret_val).padding(10).width(Units(650)).style( + >::into(StyleTuple( + style, + ElementType::BorderedRound, )), - ) + )) } } @@ -383,35 +383,32 @@ fn get_favorite_notify( let mut ret_val = Column::new().spacing(5).push(checkbox); if favorite_notification.notify_on_favorite { - let sound_row = - Row::new() - .push(horizontal_space(Length::Units(50))) - .push(sound_favorite_radios( - favorite_notification, - get_font(style), + let sound_row = Row::new() + .push(horizontal_space(Units(50))) + .push(sound_favorite_radios( + favorite_notification, + get_font(style), + style, + language, + )); + ret_val = ret_val.push(vertical_space(Units(5))).push(sound_row); + Column::new() + .padding(5) + .push(Container::new(ret_val).padding(10).width(Units(650)).style( + >::into(StyleTuple( style, - language, - )); - ret_val = ret_val - .push(vertical_space(Length::Units(5))) - .push(sound_row); - Column::new().padding(5).push( - Container::new(ret_val) - .padding(10) - .width(Length::Units(650)) - .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + ElementType::BorderedRound, )), - ) + )) } else { - Column::new().padding(5).push( - Container::new(ret_val) - .padding(10) - .width(Length::Units(650)) - .style(>::into( - StyleTuple(style, ElementType::BorderedRound), + Column::new() + .padding(5) + .push(Container::new(ret_val).padding(10).width(Units(650)).style( + >::into(StyleTuple( + style, + ElementType::BorderedRound, )), - ) + )) } } @@ -424,12 +421,23 @@ fn volume_slider(language: Language, style: StyleType, volume: u8) -> Container< .push( VerticalSlider::new(0..=100, volume, Message::ChangeVolume) .step(5) - .height(Length::Units(150)) + .height(Units(150)) .style(>::into(StyleTuple( style, ElementType::Standard, ))), ) + .push( + Text::new(if volume == 0 { + 'Y'.to_string() + } else { + 'Z'.to_string() + }) + .height(Units(30)) + .vertical_alignment(Vertical::Center) + .size(18 + u16::from(volume) * 12 / 100) + .font(ICONS), + ) .push(Text::new(volume_translation(language, volume)).font(get_font(style))), ) .width(Length::Fill) @@ -451,12 +459,12 @@ fn get_palette_container( .align_items(Alignment::Center) .spacing(5) .push(Text::new(name).font(font)) - .push(Image::new(Handle::from_memory(Vec::from(picture))).width(Length::Units(300))) + .push(Image::new(Handle::from_memory(Vec::from(picture))).width(Units(300))) .push(Text::new(description).font(font)); Button::new(content) - .height(Length::Units(130)) - .width(Length::Units(350)) + .height(Units(130)) + .width(Units(350)) .padding(10) .style(StyleTuple(style, ElementType::BorderedRound).into()) .on_press(Message::Style(on_press)) @@ -483,8 +491,8 @@ fn get_settings_header(style: StyleType, language: Language) -> Container<'stati .size(15), ) .padding(2) - .height(Length::Units(20)) - .width(Length::Units(20)) + .height(Units(20)) + .width(Units(20)) .style(StyleTuple(style, ElementType::Standard).into()) .on_press(Message::HideModal(false)), hide_translation(language), @@ -501,7 +509,7 @@ fn get_settings_header(style: StyleType, language: Language) -> Container<'stati ) .align_x(Horizontal::Center) .align_y(Vertical::Center) - .height(Length::Units(40)) + .height(Units(40)) .width(Length::Fill) .style(>::into( StyleTuple(style, ElementType::Headers), diff --git a/src/gui/styles/button.rs b/src/gui/styles/button.rs index 7d7f3669..85649fcc 100644 --- a/src/gui/styles/button.rs +++ b/src/gui/styles/button.rs @@ -57,7 +57,7 @@ fn active(&self, _: &Self::Style) -> button::Appearance { fn hovered(&self, _: &Self::Style) -> button::Appearance { let colors = get_colors(self.0); - iced::widget::button::Appearance { + button::Appearance { shadow_offset: Vector::new(2.0, 2.0), background: Some(Background::Color(match self { StyleTuple(_, ElementType::Starred) => STARRED, diff --git a/src/gui/styles/container.rs b/src/gui/styles/container.rs index 40f7270e..c216ae54 100644 --- a/src/gui/styles/container.rs +++ b/src/gui/styles/container.rs @@ -20,11 +20,11 @@ impl iced::widget::container::StyleSheet for StyleTuple { fn appearance(&self, _: &Self::Style) -> Appearance { let colors = get_colors(self.0); Appearance { - text_color: Option::Some(match self { + text_color: Some(match self { StyleTuple(_, ElementType::Headers) => colors.text_headers, _ => colors.text_body, }), - background: Option::Some(Background::Color(match self { + background: Some(Background::Color(match self { StyleTuple(_, ElementType::Headers) => colors.secondary, _ => colors.primary, })), diff --git a/src/gui/styles/slider.rs b/src/gui/styles/slider.rs index e18f8c6c..1431698c 100644 --- a/src/gui/styles/slider.rs +++ b/src/gui/styles/slider.rs @@ -16,7 +16,7 @@ fn from(tuple: StyleTuple) -> Self { impl iced::widget::slider::StyleSheet for StyleTuple { type Style = iced::Theme; - fn active(&self, _: &Self::Style) -> iced_native::widget::slider::Appearance { + fn active(&self, _: &Self::Style) -> Appearance { let colors = get_colors(self.0); Appearance { rail_colors: (colors.secondary, colors.primary), @@ -29,7 +29,7 @@ fn active(&self, _: &Self::Style) -> iced_native::widget::slider::Appearance { } } - fn hovered(&self, _: &Self::Style) -> iced_native::widget::slider::Appearance { + fn hovered(&self, _: &Self::Style) -> Appearance { let colors = get_colors(self.0); Appearance { rail_colors: (colors.secondary, colors.secondary), @@ -42,7 +42,7 @@ fn hovered(&self, _: &Self::Style) -> iced_native::widget::slider::Appearance { } } - fn dragging(&self, _: &Self::Style) -> iced_native::widget::slider::Appearance { + fn dragging(&self, _: &Self::Style) -> Appearance { let colors = get_colors(self.0); Appearance { rail_colors: (colors.secondary, colors.secondary), diff --git a/src/structs/notifications.rs b/src/structs/notifications.rs index ade8fd06..ee3f87c3 100644 --- a/src/structs/notifications.rs +++ b/src/structs/notifications.rs @@ -10,7 +10,7 @@ pub struct Notifications { pub favorite_notification: FavoriteNotification, } -impl std::default::Default for Notifications { +impl Default for Notifications { fn default() -> Self { Notifications { volume: 60, diff --git a/src/utility/manage_charts_data.rs b/src/utility/manage_charts_data.rs index 88483224..8dff54b8 100644 --- a/src/utility/manage_charts_data.rs +++ b/src/utility/manage_charts_data.rs @@ -22,7 +22,7 @@ pub fn update_charts_data(mut charts_data: RefMut) { } charts_data.sent_bytes.push_back(( tot_seconds, - ->::try_into(sent_bytes_entry).unwrap(), + ->::try_into(sent_bytes_entry).unwrap(), )); charts_data.min_sent_bytes = get_min(&charts_data.sent_bytes.clone()); charts_data.tot_sent_bytes_prev = charts_data.tot_sent_bytes; @@ -42,7 +42,7 @@ pub fn update_charts_data(mut charts_data: RefMut) { } charts_data.sent_packets.push_back(( tot_seconds, - ->::try_into(sent_packets_entry).unwrap(), + ->::try_into(sent_packets_entry).unwrap(), )); charts_data.min_sent_packets = get_min(&charts_data.sent_packets.clone()); charts_data.tot_sent_packets_prev = charts_data.tot_sent_packets; diff --git a/src/utility/manage_packets.rs b/src/utility/manage_packets.rs index 666ff310..207d70a3 100644 --- a/src/utility/manage_packets.rs +++ b/src/utility/manage_packets.rs @@ -198,7 +198,7 @@ pub fn get_capture_result(device: &Device) -> (Option, Option (Option, Option =