cargo fmt
This commit is contained in:
parent
8e57d5b165
commit
02fb6e145a
3 changed files with 69 additions and 30 deletions
|
|
@ -138,9 +138,8 @@ fn vpn_section<'a>(
|
|||
"go-down-symbolic"
|
||||
};
|
||||
|
||||
vpn_col = vpn_col.push(
|
||||
padded_control(divider::horizontal::default()).padding([space_xxs, space_s])
|
||||
);
|
||||
vpn_col = vpn_col
|
||||
.push(padded_control(divider::horizontal::default()).padding([space_xxs, space_s]));
|
||||
|
||||
let vpn_toggle_btn = menu_button(row![
|
||||
text::body(fl!("vpn-connections"))
|
||||
|
|
@ -166,17 +165,11 @@ fn vpn_section<'a>(
|
|||
.size(24)
|
||||
.symbolic(true)
|
||||
.into(),
|
||||
text::body(&vpn.name)
|
||||
.width(Length::Fill)
|
||||
.into(),
|
||||
text::body(&vpn.name).width(Length::Fill).into(),
|
||||
];
|
||||
|
||||
if is_active {
|
||||
btn_content.push(
|
||||
text::body(fl!("connected"))
|
||||
.align_x(Alignment::End)
|
||||
.into(),
|
||||
);
|
||||
btn_content.push(text::body(fl!("connected")).align_x(Alignment::End).into());
|
||||
}
|
||||
|
||||
let mut btn = menu_button(
|
||||
|
|
@ -323,9 +316,9 @@ pub(crate) enum Message {
|
|||
OpenHwDevice(Option<HwAddress>),
|
||||
TogglePasswordVisibility,
|
||||
Surface(surface::Action),
|
||||
ActivateVpn(String), // UUID of VPN to activate
|
||||
DeactivateVpn(String), // Name of VPN to deactivate
|
||||
ToggleVpnList, // Show/hide available VPNs
|
||||
ActivateVpn(String), // UUID of VPN to activate
|
||||
DeactivateVpn(String), // Name of VPN to deactivate
|
||||
ToggleVpnList, // Show/hide available VPNs
|
||||
}
|
||||
|
||||
impl cosmic::Application for CosmicNetworkApplet {
|
||||
|
|
@ -1086,7 +1079,12 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
|
||||
if !self.show_visible_networks {
|
||||
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);
|
||||
}
|
||||
|
|
@ -1234,7 +1232,12 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
|
||||
// Add VPN connections section after wireless networks when they are expanded
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,10 @@ pub async fn load_vpn_connections(conn: &Connection) -> anyhow::Result<Vec<VpnCo
|
|||
if let Some(conn_type) = &connection_settings.type_ {
|
||||
// VPN connections have type "vpn" or "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();
|
||||
|
||||
vpn_connections.push(VpnConnection { name, uuid });
|
||||
|
|
|
|||
|
|
@ -294,7 +294,9 @@ async fn start_listening(
|
|||
.send(NetworkManagerEvent::RequestResponse {
|
||||
req: NetworkManagerRequest::ActivateVpn(uuid),
|
||||
success: false,
|
||||
state: NetworkManagerState::new(&conn).await.unwrap_or_default(),
|
||||
state: NetworkManagerState::new(&conn)
|
||||
.await
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
.await;
|
||||
return State::Waiting(conn, rx);
|
||||
|
|
@ -316,16 +318,31 @@ async fn start_listening(
|
|||
use zbus::zvariant::ObjectPath;
|
||||
let empty_device = ObjectPath::try_from("/").unwrap();
|
||||
|
||||
match network_manager.inner()
|
||||
.call_method("ActivateConnection", &(connection.inner().path(), empty_device.clone(), empty_device))
|
||||
match network_manager
|
||||
.inner()
|
||||
.call_method(
|
||||
"ActivateConnection",
|
||||
&(
|
||||
connection.inner().path(),
|
||||
empty_device.clone(),
|
||||
empty_device,
|
||||
),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
tracing::info!("Successfully activated VPN: {}", uuid);
|
||||
tracing::info!(
|
||||
"Successfully activated VPN: {}",
|
||||
uuid
|
||||
);
|
||||
success = true;
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to activate VPN {}: {:?}", uuid, e);
|
||||
tracing::error!(
|
||||
"Failed to activate VPN {}: {:?}",
|
||||
uuid,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -337,7 +354,10 @@ async fn start_listening(
|
|||
}
|
||||
|
||||
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();
|
||||
|
|
@ -359,7 +379,9 @@ async fn start_listening(
|
|||
.send(NetworkManagerEvent::RequestResponse {
|
||||
req: NetworkManagerRequest::DeactivateVpn(name),
|
||||
success: false,
|
||||
state: NetworkManagerState::new(&conn).await.unwrap_or_default(),
|
||||
state: NetworkManagerState::new(&conn)
|
||||
.await
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
.await;
|
||||
return State::Waiting(conn, rx);
|
||||
|
|
@ -373,14 +395,22 @@ async fn start_listening(
|
|||
for active_conn in active_connections {
|
||||
if let Ok(conn_id) = active_conn.id().await {
|
||||
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(_) => {
|
||||
tracing::info!("Successfully deactivated VPN: {}", name);
|
||||
tracing::info!(
|
||||
"Successfully deactivated VPN: {}",
|
||||
name
|
||||
);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
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 {
|
||||
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();
|
||||
|
|
@ -479,8 +512,8 @@ pub enum NetworkManagerRequest {
|
|||
},
|
||||
Forget(String, HwAddress),
|
||||
Reload,
|
||||
ActivateVpn(String), // UUID of VPN connection to activate
|
||||
DeactivateVpn(String), // Name of active VPN connection to deactivate
|
||||
ActivateVpn(String), // UUID of VPN connection to activate
|
||||
DeactivateVpn(String), // Name of active VPN connection to deactivate
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue