diff --git a/src/gui/components/footer.rs b/src/gui/components/footer.rs index 65408353..8ff4e1a4 100644 --- a/src/gui/components/footer.rs +++ b/src/gui/components/footer.rs @@ -15,6 +15,7 @@ use crate::gui::types::message::Message; use crate::translations::translations_2::new_version_available_translation; use crate::utils::formatted_strings::APP_VERSION; +use crate::utils::types::web_page::WebPage; use crate::Language; pub fn footer( @@ -62,7 +63,7 @@ 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()) - .on_press(Message::OpenGithub(true)); + .on_press(Message::OpenWebPage(WebPage::Repo)); Tooltip::new(content, "GitHub", Position::Top) .font(get_font(style)) @@ -100,7 +101,7 @@ fn get_release_details( .height(Length::Fixed(40.0)) .width(Length::Fixed(40.0)) .style(StyleTuple(style, ElementType::Alert).into()) - .on_press(Message::OpenGithub(false)); + .on_press(Message::OpenWebPage(WebPage::WebsiteDownload)); let tooltip = Tooltip::new( button, new_version_available_translation(language), diff --git a/src/gui/types/message.rs b/src/gui/types/message.rs index e80700fe..229fed37 100644 --- a/src/gui/types/message.rs +++ b/src/gui/types/message.rs @@ -4,6 +4,7 @@ use crate::networking::types::host::Host; use crate::networking::types::search_parameters::SearchParameters; use crate::notifications::types::notifications::Notification; +use crate::utils::types::web_page::WebPage; use crate::{ AppProtocol, ChartType, IpVersion, Language, ReportSortType, StyleType, TransProtocol, }; @@ -31,8 +32,8 @@ pub enum Message { AddOrRemoveFavorite(Host, bool), /// Open Sniffnet's complete textual report OpenReport, - /// Open Sniffnet's GitHub main page if true is passed, latest release page otherwise - OpenGithub(bool), + /// Open the supplied web page + OpenWebPage(WebPage), /// Start sniffing packets Start, /// Stop sniffing process and return to initial page diff --git a/src/gui/types/sniffer.rs b/src/gui/types/sniffer.rs index 0f4a13e5..540d82db 100644 --- a/src/gui/types/sniffer.rs +++ b/src/gui/types/sniffer.rs @@ -28,6 +28,7 @@ use crate::secondary_threads::parse_packets::parse_packets; use crate::translations::types::language::Language; use crate::utils::formatted_strings::get_report_path; +use crate::utils::types::web_page::WebPage; use crate::{ConfigDevice, ConfigSettings, InfoTraffic, RunTimeData, StyleType, TrafficChart}; /// Struct on which the gui is based @@ -133,7 +134,7 @@ pub fn update(&mut self, message: Message) -> Command { self.report_sort_type = what_to_display; } Message::OpenReport => self.open_report_file(), - Message::OpenGithub(main_page) => Self::open_github(main_page), + Message::OpenWebPage(web_page) => Self::open_web(web_page), Message::Start => self.start(), Message::Reset => return self.reset(), Message::Style(style) => { @@ -288,12 +289,8 @@ fn open_report_file(&mut self) { } } - fn open_github(main_page: bool) { - let url = if main_page { - "https://github.com/GyulyVGC/sniffnet" - } else { - "https://github.com/GyulyVGC/sniffnet/releases/latest" - }; + fn open_web(web_page: WebPage) { + let url = web_page.get_url(); #[cfg(target_os = "windows")] std::process::Command::new("explorer") .arg(url) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 48784303..4723e024 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,4 @@ pub mod asn; pub mod countries; pub mod formatted_strings; +pub mod types; diff --git a/src/utils/types/mod.rs b/src/utils/types/mod.rs new file mode 100644 index 00000000..18b08031 --- /dev/null +++ b/src/utils/types/mod.rs @@ -0,0 +1 @@ +pub mod web_page; diff --git a/src/utils/types/web_page.rs b/src/utils/types/web_page.rs new file mode 100644 index 00000000..d0718dea --- /dev/null +++ b/src/utils/types/web_page.rs @@ -0,0 +1,17 @@ +/// This enum defines the possible web pages to be opened. +#[derive(Debug, Clone)] +pub enum WebPage { + /// Sniffnet's GitHub repository. + Repo, + /// Sniffnet's website/download page. + WebsiteDownload, +} + +impl WebPage { + pub fn get_url(&self) -> &str { + match self { + WebPage::Repo => "https://github.com/GyulyVGC/sniffnet", + WebPage::WebsiteDownload => "https://www.sniffnet.net/download/", + } + } +}