Skip to content

Commit 87d149c

Browse files
committed
Refactor: Simplify conditional logic for VPN import and disconnection handling
1 parent 85e2bc9 commit 87d149c

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/app.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,13 +786,13 @@ impl App {
786786
break;
787787
}
788788

789-
if let Ok(active) = vpn_manager.get_active_vpns().await {
790-
if active.iter().any(|(name, _)| name != &profile_name) {
791-
let _ = event_tx.send(AppEvent::Notification("Another active VPN detected during stabilization. Ensuring exclusivity...".to_string())).await;
792-
for (name, _) in active {
793-
if name != profile_name {
794-
let _ = vpn_manager.disconnect(&name).await;
795-
}
789+
if let Ok(active) = vpn_manager.get_active_vpns().await
790+
&& active.iter().any(|(name, _)| name != &profile_name)
791+
{
792+
let _ = event_tx.send(AppEvent::Notification("Another active VPN detected during stabilization. Ensuring exclusivity...".to_string())).await;
793+
for (name, _) in active {
794+
if name != profile_name {
795+
let _ = vpn_manager.disconnect(&name).await;
796796
}
797797
}
798798
}

src/bin/remipn.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,12 @@ async fn cmd_connect(name: String) -> Result<()> {
398398
}
399399

400400
// ensure no other VPN is active
401-
if let Ok(active) = mgr.get_active_vpns().await {
402-
if active.iter().any(|(name, _)| name != &profile_name) {
403-
for (name, _) in active {
404-
if name != profile_name {
405-
let _ = mgr.disconnect(&name).await;
406-
}
401+
if let Ok(active) = mgr.get_active_vpns().await
402+
&& active.iter().any(|(name, _)| name != &profile_name)
403+
{
404+
for (name, _) in active {
405+
if name != profile_name {
406+
let _ = mgr.disconnect(&name).await;
407407
}
408408
}
409409
}

src/config.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,20 @@ impl Config {
9191
let mut imported_any = false;
9292

9393
// Import from default import dir
94-
if let Ok(import_dir) = Self::import_dir() {
95-
if self.import_from_dir(&import_dir)? {
96-
imported_any = true;
97-
}
94+
if let Ok(import_dir) = Self::import_dir()
95+
&& self.import_from_dir(&import_dir)?
96+
{
97+
imported_any = true;
9898
}
9999

100100
// Import from Azure VPN Client dir on macOS
101101
#[cfg(target_os = "macos")]
102102
{
103-
if let Ok(azure_dir) = Self::azure_vpn_import_dir() {
104-
if azure_dir.exists() {
105-
if self.import_from_dir(&azure_dir)? {
106-
imported_any = true;
107-
}
108-
}
103+
if let Ok(azure_dir) = Self::azure_vpn_import_dir()
104+
&& azure_dir.exists()
105+
&& self.import_from_dir(&azure_dir)?
106+
{
107+
imported_any = true;
109108
}
110109
}
111110

0 commit comments

Comments
 (0)