Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrinux committed Jul 19, 2024
1 parent a6d809c commit 6a73a26
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/iwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,25 @@ fn attempt_connection(
ssid: &str,
passphrase: Option<String>,
) -> Result<bool, Box<dyn std::error::Error>> {
let command = match passphrase {
Some(ref pwd) => format!("--passphrase '{pwd}' station {interface} connect '{ssid}'"),
None => format!("station {interface} connect '{ssid}'"),
};
let mut command_args = vec![
"station".to_string(),
interface.to_string(),
"connect".to_string(),
ssid.to_string(),
];
if let Some(pwd) = passphrase {
command_args.push("--passphrase".to_string());
command_args.push(pwd);
}

let status = Command::new("iwctl").args(command.split(' ')).status()?;
let status = Command::new("iwctl").args(&command_args).status()?;

if status.success() {
notify_connection(ssid)?;
Ok(true)
} else {
#[cfg(debug_assertions)]
eprintln!("Failed to connect to Wi-Fi network: {ssid}");
eprintln!("Failed to connect to Wi-Fi network: {}", ssid);
Ok(false)
}
}
Expand Down

0 comments on commit 6a73a26

Please sign in to comment.