Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[![CI](https://github.com/aashish-thapa/wlctl/actions/workflows/ci.yaml/badge.svg)](https://github.com/aashish-thapa/wlctl/actions/workflows/ci.yaml)
[![Crates.io](https://img.shields.io/crates/v/wlctl.svg)](https://crates.io/crates/wlctl)
[![Downloads](https://img.shields.io/crates/d/wlctl.svg)](https://crates.io/crates/impala-nm)
[![Downloads](https://img.shields.io/crates/d/wlctl.svg)](https://crates.io/crates/wlctl)
[![License](https://img.shields.io/crates/l/wlctl.svg)](https://github.com/aashish-thapa/wlctl/blob/main/LICENSE)
</div>

Expand Down Expand Up @@ -92,6 +92,10 @@ This will produce an executable file at `target/release/wlctl` that you can copy

`Space or Enter`: Connect/Disconnect the network.

### New Networks

`h`: Connect to a hidden network.

### Known Networks

`t`: Enable/Disable auto-connect.
Expand Down Expand Up @@ -132,6 +136,10 @@ stop = 'x'
[station]
toggle_scanning = "s"

[station.new_network]
show_all = "a"
connect_hidden = "h"

[station.known_network]
toggle_autoconnect = "t"
remove = "d"
Expand Down
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum FocusedBlock {
RequestUsernameAndPassword,
ShareNetwork,
SpeedTest,
HiddenSsidInput,
}

pub struct App {
Expand Down
11 changes: 10 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,23 @@ fn default_station_remove_known_network() -> char {
#[derive(Deserialize, Debug)]
pub struct NewNetwork {
pub show_all: char,
#[serde(default = "default_connect_hidden")]
pub connect_hidden: char,
}

impl Default for NewNetwork {
fn default() -> Self {
Self { show_all: 'a' }
Self {
show_all: 'a',
connect_hidden: 'h',
}
}
}

fn default_connect_hidden() -> char {
'h'
}

// Access Point
#[derive(Deserialize, Debug)]
pub struct AccessPoint {
Expand Down
113 changes: 113 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,113 @@ pub async fn handle_key_events(
Mode::Station => {
if let Some(station) = &mut app.device.station {
match app.focused_block {
FocusedBlock::HiddenSsidInput => match key_event.code {
KeyCode::Enter => {
let ssid: String = app.auth.hidden.ssid.value().into();
let password: String = app.auth.hidden.password.value().into();

if ssid.is_empty() {
Notification::send(
"SSID cannot be empty".to_string(),
notification::NotificationLevel::Warning,
&sender,
)?;
} else if app.auth.hidden.requires_password() && password.is_empty() {
Notification::send(
"Password cannot be empty".to_string(),
notification::NotificationLevel::Warning,
&sender,
)?;
} else {
let security = app.auth.hidden.security;
let password = if app.auth.hidden.requires_password() {
Some(password)
} else {
None
};

let station_client = station.client.clone();
let device_path = station.device_path.clone();
let sender_clone = sender.clone();
app.auth.hidden.reset();
app.focused_block = FocusedBlock::NewNetworks;
tokio::spawn(async move {
let _ = station_client
.add_and_activate_hidden_connection(
&device_path,
&ssid,
security,
password.as_deref(),
)
.await
.map(|_| {
let _ = Notification::send(
format!("Connecting to hidden network: {}", ssid),
notification::NotificationLevel::Info,
&sender_clone,
);
})
.map_err(|e| {
let _ = Notification::send(
format!("Failed to connect to {}: {}", ssid, e),
notification::NotificationLevel::Error,
&sender_clone,
);
});
});
}
}

KeyCode::Tab => {
app.auth.hidden.next_field();
}

KeyCode::BackTab => {
app.auth.hidden.prev_field();
}

KeyCode::Right => {
if app.auth.hidden.focused_field
== crate::mode::station::auth::hidden::HiddenField::Security
{
app.auth.hidden.cycle_security_next();
}
}

KeyCode::Left => {
if app.auth.hidden.focused_field
== crate::mode::station::auth::hidden::HiddenField::Security
{
app.auth.hidden.cycle_security_prev();
}
}

KeyCode::Esc => {
app.auth.hidden.reset();
app.focused_block = FocusedBlock::NewNetworks;
}

KeyCode::Char('h') if key_event.modifiers == KeyModifiers::CONTROL => {
app.auth.hidden.show_password = !app.auth.hidden.show_password;
}

_ => match app.auth.hidden.focused_field {
crate::mode::station::auth::hidden::HiddenField::Ssid => {
app.auth
.hidden
.ssid
.handle_event(&crossterm::event::Event::Key(key_event));
}
crate::mode::station::auth::hidden::HiddenField::Password => {
app.auth
.hidden
.password
.handle_event(&crossterm::event::Event::Key(key_event));
}
_ => {}
},
},

FocusedBlock::PskAuthKey => match key_event.code {
KeyCode::Enter => {
// Get the password before submit() resets it
Expand Down Expand Up @@ -641,6 +748,12 @@ pub async fn handle_key_events(
station.show_hidden_networks =
!station.show_hidden_networks;
}
// Connect to hidden network
KeyCode::Char(c)
if c == config.station.new_network.connect_hidden =>
{
app.focused_block = FocusedBlock::HiddenSsidInput;
}
KeyCode::Enter | KeyCode::Char(' ') => {
toggle_connect(app, sender).await?
}
Expand Down
20 changes: 7 additions & 13 deletions src/mode/station.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,6 @@ impl Station {
})
}

pub async fn connect_hidden_network(
&self,
_ssid: String,
_password: Option<&str>,
) -> Result<()> {
// For hidden networks, we need to create a connection with the hidden flag
// This is handled by add_and_activate_connection with special settings
// For now, we'll return an error - full hidden network support needs more work
Err(anyhow::anyhow!(
"Hidden network connection not yet implemented for NetworkManager"
))
}

#[allow(clippy::collapsible_if)]
pub async fn refresh(&mut self) -> Result<()> {
let device_state = self.client.get_device_state(&self.device_path).await?;
Expand Down Expand Up @@ -872,6 +859,10 @@ impl Station {
Span::from("󱁐 or ↵ ").bold(),
Span::from(" Connect"),
Span::from(" | "),
Span::from(config.station.new_network.connect_hidden.to_string())
.bold(),
Span::from(" Hidden"),
Span::from(" | "),
Span::from(config.station.start_scanning.to_string()).bold(),
Span::from(" Scan"),
]),
Expand Down Expand Up @@ -900,6 +891,9 @@ impl Station {
Span::from("󱁐 or ↵ ").bold(),
Span::from(" Connect"),
Span::from(" | "),
Span::from(config.station.new_network.connect_hidden.to_string()).bold(),
Span::from(" Hidden"),
Span::from(" | "),
Span::from(config.station.new_network.show_all.to_string()).bold(),
Span::from(" Show All"),
Span::from(" | "),
Expand Down
4 changes: 4 additions & 0 deletions src/mode/station/auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod entreprise;
pub mod hidden;
pub mod psk;

use std::sync::Arc;
Expand All @@ -11,13 +12,15 @@ use crate::mode::station::auth::{
username_and_password::RequestUsernameAndPassword,
},
},
hidden::HiddenSsidDialog,
psk::Psk,
};
use crate::nm::NMClient;

#[derive(Debug, Default)]
pub struct Auth {
pub psk: Psk,
pub hidden: HiddenSsidDialog,
pub eap: Option<WPAEntreprise>,
pub request_key_passphrase: Option<RequestKeyPassphrase>,
pub request_password: Option<RequestPassword>,
Expand All @@ -31,6 +34,7 @@ impl Auth {

pub fn reset(&mut self) {
self.psk = Psk::default();
self.hidden.reset();
self.eap = None;
}

Expand Down
Loading