Skip to main content

tauri_plugin_network_manager/
models.rs

1use serde::{Deserialize, Serialize};
2use tauri::{AppHandle, Runtime};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct NetworkInfo {
6    pub name: String,
7    pub ssid: String,
8    pub connection_type: String,
9    pub icon: String,
10    pub ip_address: String,
11    pub mac_address: String,
12    pub signal_strength: u8,
13    pub security_type: WiFiSecurityType,
14    pub is_connected: bool,
15}
16
17impl Default for NetworkInfo {
18    fn default() -> Self {
19        Self {
20            name: String::from("Unknown"),
21            ssid: String::from("Unknown"),
22            connection_type: String::from("Unknown"),
23            icon: String::from("network-offline-symbolic"), // icono por defecto
24            ip_address: String::from("0.0.0.0"),
25            mac_address: String::from("00:00:00:00:00:00"),
26            signal_strength: 0,
27            security_type: WiFiSecurityType::None,
28            is_connected: false,
29        }
30    }
31}
32
33#[derive(Serialize, Deserialize, Debug, Clone)]
34#[serde(rename_all = "kebab-case")]
35pub enum WiFiSecurityType {
36    None,
37    Wep,
38    WpaPsk,
39    WpaEap,
40    Wpa2Psk,
41    Wpa3Psk,
42}
43
44#[derive(Serialize, Deserialize, Debug, Clone, Default)]
45pub struct WiFiNetwork {
46    pub ssid: String,
47    pub signal_strength: u8,
48    pub icon: String,
49}
50
51#[derive(Serialize, Deserialize, Debug)]
52pub struct WiFiConnectionConfig {
53    pub ssid: String,
54    pub password: Option<String>,
55    pub security_type: WiFiSecurityType,
56    pub username: Option<String>,
57}
58
59#[derive(Serialize, Deserialize, Debug, Clone)]
60#[serde(rename_all = "kebab-case")]
61pub enum VpnType {
62    OpenVpn,
63    WireGuard,
64    L2tp,
65    Pptp,
66    Sstp,
67    Ikev2,
68    Fortisslvpn,
69    OpenConnect,
70    Generic,
71}
72
73#[derive(Serialize, Deserialize, Debug, Clone)]
74pub struct VpnProfile {
75    pub id: String,
76    pub uuid: String,
77    pub vpn_type: VpnType,
78    pub interface_name: Option<String>,
79    pub autoconnect: bool,
80    pub editable: bool,
81    pub last_error: Option<String>,
82}
83
84#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
85#[serde(rename_all = "kebab-case")]
86pub enum VpnConnectionState {
87    Disconnected,
88    Connecting,
89    Connected,
90    Disconnecting,
91    Failed,
92    Unknown,
93}
94
95#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
96pub struct VpnStatus {
97    pub state: VpnConnectionState,
98    pub active_profile_id: Option<String>,
99    pub active_profile_uuid: Option<String>,
100    pub active_profile_name: Option<String>,
101    pub ip_address: Option<String>,
102    pub gateway: Option<String>,
103    pub since_unix_ms: Option<u64>,
104}
105
106#[derive(Serialize, Deserialize, Debug, Clone)]
107pub struct VpnEventPayload {
108    pub status: VpnStatus,
109    pub profile: Option<VpnProfile>,
110    pub reason: Option<String>,
111}
112
113impl Default for VpnStatus {
114    fn default() -> Self {
115        Self {
116            state: VpnConnectionState::Disconnected,
117            active_profile_id: None,
118            active_profile_uuid: None,
119            active_profile_name: None,
120            ip_address: None,
121            gateway: None,
122            since_unix_ms: None,
123        }
124    }
125}
126
127#[derive(Deserialize, Clone)]
128pub struct VpnCreateConfig {
129    pub id: String,
130    pub vpn_type: VpnType,
131    pub autoconnect: Option<bool>,
132    pub username: Option<String>,
133    pub password: Option<String>,
134    pub gateway: Option<String>,
135    pub ca_cert_path: Option<String>,
136    pub user_cert_path: Option<String>,
137    pub private_key_path: Option<String>,
138    pub private_key_password: Option<String>,
139    pub settings: Option<std::collections::HashMap<String, String>>,
140    pub secrets: Option<std::collections::HashMap<String, String>>,
141}
142
143#[derive(Deserialize, Clone)]
144pub struct VpnUpdateConfig {
145    pub uuid: String,
146    pub id: Option<String>,
147    pub autoconnect: Option<bool>,
148    pub username: Option<String>,
149    pub password: Option<String>,
150    pub gateway: Option<String>,
151    pub ca_cert_path: Option<String>,
152    pub user_cert_path: Option<String>,
153    pub private_key_path: Option<String>,
154    pub private_key_password: Option<String>,
155    pub settings: Option<std::collections::HashMap<String, String>>,
156    pub secrets: Option<std::collections::HashMap<String, String>>,
157}
158
159/// Network statistics for bandwidth monitoring
160#[derive(Serialize, Deserialize, Debug, Clone)]
161pub struct NetworkStats {
162    /// Current download speed in bytes per second
163    pub download_speed: u64,
164    /// Current upload speed in bytes per second
165    pub upload_speed: u64,
166    /// Total bytes downloaded since connection
167    pub total_downloaded: u64,
168    /// Total bytes uploaded since connection
169    pub total_uploaded: u64,
170    /// Connection duration in seconds
171    pub connection_duration: u64,
172    /// Network interface name
173    pub interface: String,
174}
175
176/// Bandwidth data point for historical tracking
177#[derive(Serialize, Deserialize, Debug, Clone)]
178pub struct BandwidthPoint {
179    /// Timestamp in seconds since epoch
180    pub timestamp: u64,
181    /// Download speed in bytes per second
182    pub download_speed: u64,
183    /// Upload speed in bytes per second
184    pub upload_speed: u64,
185}
186
187// Removed duplicate init function
188
189#[derive(Clone, Debug)]
190pub struct VSKNetworkManager<'a, R: Runtime> {
191    pub connection: zbus::blocking::Connection,
192    pub proxy: zbus::blocking::fdo::PropertiesProxy<'a>,
193    pub app: AppHandle<R>,
194}