forked from GyulyVGC/sniffnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
132 lines (116 loc) · 4.48 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! Module containing the entry point of application execution.
use std::borrow::Cow;
use std::sync::{Arc, Mutex};
use std::{panic, process, thread};
#[cfg(target_os = "linux")]
use iced::window::settings::PlatformSpecific;
use iced::{application, window, Font, Pixels, Settings};
use chart::types::chart_type::ChartType;
use chart::types::traffic_chart::TrafficChart;
use cli::parse_cli_args;
use configs::types::config_device::ConfigDevice;
use configs::types::config_settings::ConfigSettings;
use gui::pages::types::running_page::RunningPage;
use gui::sniffer::Sniffer;
use gui::styles::style_constants::FONT_SIZE_BODY;
use gui::styles::types::style_type::StyleType;
use gui::types::runtime_data::RunTimeData;
use networking::types::byte_multiple::ByteMultiple;
use networking::types::info_traffic::InfoTraffic;
use networking::types::ip_version::IpVersion;
use networking::types::protocol::Protocol;
use networking::types::service::Service;
use report::types::report_sort_type::ReportSortType;
use translations::types::language::Language;
use utils::formatted_strings::print_cli_welcome_message;
use crate::configs::types::config_window::{ConfigWindow, ToPosition, ToSize};
use crate::configs::types::configs::{Configs, CONFIGS};
use crate::gui::sniffer::FONT_FAMILY_NAME;
use crate::gui::styles::style_constants::{ICONS_BYTES, SARASA_MONO_BOLD_BYTES, SARASA_MONO_BYTES};
use crate::secondary_threads::check_updates::set_newer_release_status;
mod chart;
mod cli;
mod configs;
mod countries;
mod gui;
mod mmdb;
mod networking;
mod notifications;
mod report;
mod secondary_threads;
mod translations;
mod utils;
pub const SNIFFNET_LOWERCASE: &str = "sniffnet";
pub const SNIFFNET_TITLECASE: &str = "Sniffnet";
/// Entry point of application execution
///
/// It initializes shared variables and loads configuration parameters
pub fn main() -> iced::Result {
let configs = CONFIGS.clone();
let boot_task_chain = parse_cli_args();
let configs1 = Arc::new(Mutex::new(configs));
let configs2 = configs1.clone();
let newer_release_available1 = Arc::new(Mutex::new(None));
let newer_release_available2 = newer_release_available1.clone();
// kill the main thread as soon as a secondary thread panics
let orig_hook = panic::take_hook();
panic::set_hook(Box::new(move |panic_info| {
// invoke the default handler and exit the process
orig_hook(panic_info);
process::exit(1);
}));
// gracefully close the app when receiving SIGINT, SIGTERM, or SIGHUP
ctrlc::set_handler(move || {
configs2.lock().unwrap().clone().store();
process::exit(130);
})
.expect("Error setting Ctrl-C handler");
thread::Builder::new()
.name("thread_check_updates".to_string())
.spawn(move || {
set_newer_release_status(&newer_release_available2);
})
.unwrap();
print_cli_welcome_message();
let ConfigWindow { size, position, .. } = configs1.lock().unwrap().window;
application(SNIFFNET_TITLECASE, Sniffer::update, Sniffer::view)
.settings(Settings {
// id needed for Linux Wayland; should match StartupWMClass in .desktop file; see issue #292
id: Some(String::from(SNIFFNET_LOWERCASE)),
fonts: vec![
Cow::Borrowed(SARASA_MONO_BYTES),
Cow::Borrowed(SARASA_MONO_BOLD_BYTES),
Cow::Borrowed(ICONS_BYTES),
],
default_font: Font::with_name(FONT_FAMILY_NAME),
default_text_size: Pixels(FONT_SIZE_BODY),
antialiasing: false,
})
.window(window::Settings {
size: size.to_size(), // start size
position: position.to_position(),
min_size: None, // Some(ConfigWindow::MIN_SIZE.to_size()), // min size allowed
max_size: None,
visible: true,
resizable: true,
decorations: true,
transparent: false,
icon: None,
#[cfg(target_os = "linux")]
platform_specific: PlatformSpecific {
application_id: String::from(SNIFFNET_LOWERCASE),
..PlatformSpecific::default()
},
exit_on_close_request: false,
..Default::default()
})
.subscription(Sniffer::subscription)
.theme(Sniffer::theme)
.scale_factor(Sniffer::scale_factor)
.run_with(move || {
(
Sniffer::new(&configs1, newer_release_available1),
boot_task_chain,
)
})
}