cargo fmt

This commit is contained in:
Vukašin Vojinović 2025-10-08 16:45:44 +02:00 committed by Ashley Wulber
parent 8e57d5b165
commit 02fb6e145a
3 changed files with 69 additions and 30 deletions

View file

@ -138,9 +138,8 @@ fn vpn_section<'a>(
"go-down-symbolic" "go-down-symbolic"
}; };
vpn_col = vpn_col.push( vpn_col = vpn_col
padded_control(divider::horizontal::default()).padding([space_xxs, space_s]) .push(padded_control(divider::horizontal::default()).padding([space_xxs, space_s]));
);
let vpn_toggle_btn = menu_button(row![ let vpn_toggle_btn = menu_button(row![
text::body(fl!("vpn-connections")) text::body(fl!("vpn-connections"))
@ -166,17 +165,11 @@ fn vpn_section<'a>(
.size(24) .size(24)
.symbolic(true) .symbolic(true)
.into(), .into(),
text::body(&vpn.name) text::body(&vpn.name).width(Length::Fill).into(),
.width(Length::Fill)
.into(),
]; ];
if is_active { if is_active {
btn_content.push( btn_content.push(text::body(fl!("connected")).align_x(Alignment::End).into());
text::body(fl!("connected"))
.align_x(Alignment::End)
.into(),
);
} }
let mut btn = menu_button( let mut btn = menu_button(
@ -323,9 +316,9 @@ pub(crate) enum Message {
OpenHwDevice(Option<HwAddress>), OpenHwDevice(Option<HwAddress>),
TogglePasswordVisibility, TogglePasswordVisibility,
Surface(surface::Action), Surface(surface::Action),
ActivateVpn(String), // UUID of VPN to activate ActivateVpn(String), // UUID of VPN to activate
DeactivateVpn(String), // Name of VPN to deactivate DeactivateVpn(String), // Name of VPN to deactivate
ToggleVpnList, // Show/hide available VPNs ToggleVpnList, // Show/hide available VPNs
} }
impl cosmic::Application for CosmicNetworkApplet { impl cosmic::Application for CosmicNetworkApplet {
@ -1086,7 +1079,12 @@ impl cosmic::Application for CosmicNetworkApplet {
if !self.show_visible_networks { if !self.show_visible_networks {
if !self.nm_state.available_vpns.is_empty() { if !self.nm_state.available_vpns.is_empty() {
content = content.push(vpn_section(&self.nm_state, self.show_available_vpns, space_xxs, space_s)); content = content.push(vpn_section(
&self.nm_state,
self.show_available_vpns,
space_xxs,
space_s,
));
} }
return self.view_window_return(content); return self.view_window_return(content);
} }
@ -1234,7 +1232,12 @@ impl cosmic::Application for CosmicNetworkApplet {
// Add VPN connections section after wireless networks when they are expanded // Add VPN connections section after wireless networks when they are expanded
if !self.nm_state.available_vpns.is_empty() { if !self.nm_state.available_vpns.is_empty() {
content = content.push(vpn_section(&self.nm_state, self.show_available_vpns, space_xxs, space_s)); content = content.push(vpn_section(
&self.nm_state,
self.show_available_vpns,
space_xxs,
space_s,
));
} }
self.view_window_return(content) self.view_window_return(content)

View file

@ -29,7 +29,10 @@ pub async fn load_vpn_connections(conn: &Connection) -> anyhow::Result<Vec<VpnCo
if let Some(conn_type) = &connection_settings.type_ { if let Some(conn_type) = &connection_settings.type_ {
// VPN connections have type "vpn" or "wireguard" // VPN connections have type "vpn" or "wireguard"
if conn_type == "vpn" || conn_type == "wireguard" { if conn_type == "vpn" || conn_type == "wireguard" {
let name = connection_settings.id.clone().unwrap_or_else(|| "Unknown VPN".to_string()); let name = connection_settings
.id
.clone()
.unwrap_or_else(|| "Unknown VPN".to_string());
let uuid = connection_settings.uuid.clone().unwrap_or_default(); let uuid = connection_settings.uuid.clone().unwrap_or_default();
vpn_connections.push(VpnConnection { name, uuid }); vpn_connections.push(VpnConnection { name, uuid });

View file

@ -294,7 +294,9 @@ async fn start_listening(
.send(NetworkManagerEvent::RequestResponse { .send(NetworkManagerEvent::RequestResponse {
req: NetworkManagerRequest::ActivateVpn(uuid), req: NetworkManagerRequest::ActivateVpn(uuid),
success: false, success: false,
state: NetworkManagerState::new(&conn).await.unwrap_or_default(), state: NetworkManagerState::new(&conn)
.await
.unwrap_or_default(),
}) })
.await; .await;
return State::Waiting(conn, rx); return State::Waiting(conn, rx);
@ -316,16 +318,31 @@ async fn start_listening(
use zbus::zvariant::ObjectPath; use zbus::zvariant::ObjectPath;
let empty_device = ObjectPath::try_from("/").unwrap(); let empty_device = ObjectPath::try_from("/").unwrap();
match network_manager.inner() match network_manager
.call_method("ActivateConnection", &(connection.inner().path(), empty_device.clone(), empty_device)) .inner()
.call_method(
"ActivateConnection",
&(
connection.inner().path(),
empty_device.clone(),
empty_device,
),
)
.await .await
{ {
Ok(_) => { Ok(_) => {
tracing::info!("Successfully activated VPN: {}", uuid); tracing::info!(
"Successfully activated VPN: {}",
uuid
);
success = true; success = true;
} }
Err(e) => { Err(e) => {
tracing::error!("Failed to activate VPN {}: {:?}", uuid, e); tracing::error!(
"Failed to activate VPN {}: {:?}",
uuid,
e
);
} }
} }
break; break;
@ -337,7 +354,10 @@ async fn start_listening(
} }
if !success { if !success {
tracing::warn!("VPN connection with UUID {} not found or failed to activate", uuid); tracing::warn!(
"VPN connection with UUID {} not found or failed to activate",
uuid
);
} }
let state = NetworkManagerState::new(&conn).await.unwrap_or_default(); let state = NetworkManagerState::new(&conn).await.unwrap_or_default();
@ -359,7 +379,9 @@ async fn start_listening(
.send(NetworkManagerEvent::RequestResponse { .send(NetworkManagerEvent::RequestResponse {
req: NetworkManagerRequest::DeactivateVpn(name), req: NetworkManagerRequest::DeactivateVpn(name),
success: false, success: false,
state: NetworkManagerState::new(&conn).await.unwrap_or_default(), state: NetworkManagerState::new(&conn)
.await
.unwrap_or_default(),
}) })
.await; .await;
return State::Waiting(conn, rx); return State::Waiting(conn, rx);
@ -373,14 +395,22 @@ async fn start_listening(
for active_conn in active_connections { for active_conn in active_connections {
if let Ok(conn_id) = active_conn.id().await { if let Ok(conn_id) = active_conn.id().await {
if conn_id == name && active_conn.vpn().await.unwrap_or(false) { if conn_id == name && active_conn.vpn().await.unwrap_or(false) {
match network_manager.deactivate_connection(&active_conn).await { match network_manager.deactivate_connection(&active_conn).await
{
Ok(_) => { Ok(_) => {
tracing::info!("Successfully deactivated VPN: {}", name); tracing::info!(
"Successfully deactivated VPN: {}",
name
);
success = true; success = true;
break; break;
} }
Err(e) => { Err(e) => {
tracing::error!("Failed to deactivate VPN {}: {:?}", name, e); tracing::error!(
"Failed to deactivate VPN {}: {:?}",
name,
e
);
} }
} }
} }
@ -389,7 +419,10 @@ async fn start_listening(
} }
if !success { if !success {
tracing::warn!("Active VPN connection '{}' not found or failed to deactivate", name); tracing::warn!(
"Active VPN connection '{}' not found or failed to deactivate",
name
);
} }
let state = NetworkManagerState::new(&conn).await.unwrap_or_default(); let state = NetworkManagerState::new(&conn).await.unwrap_or_default();
@ -479,8 +512,8 @@ pub enum NetworkManagerRequest {
}, },
Forget(String, HwAddress), Forget(String, HwAddress),
Reload, Reload,
ActivateVpn(String), // UUID of VPN connection to activate ActivateVpn(String), // UUID of VPN connection to activate
DeactivateVpn(String), // Name of active VPN connection to deactivate DeactivateVpn(String), // Name of active VPN connection to deactivate
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]