feat: created WebPage enum to manage URLs related info

This commit is contained in:
Giuliano Bellini s294739
2023-05-23 12:00:23 +02:00
parent f31d558bdd
commit cc3e99e080
6 changed files with 29 additions and 11 deletions

View File

@@ -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),

View File

@@ -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

View File

@@ -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<Message> {
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)

View File

@@ -1,3 +1,4 @@
pub mod asn;
pub mod countries;
pub mod formatted_strings;
pub mod types;

1
src/utils/types/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod web_page;

View File

@@ -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/",
}
}
}