Skip to content

fix: network-manager was not listening to device changes #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
54 changes: 27 additions & 27 deletions src/services/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,18 @@ impl NetworkService {
})
.boxed();

// When devices list change I need to update the wireless device state changes
let wireless_ac = nm.wireless_access_points().await?;

// When devices list change I need to update the wireless device state changes
let mut device_state_changes = Vec::with_capacity(wireless_ac.len());
// When devices list change I need to update the access points changes
let mut ac_changes = Vec::with_capacity(wireless_ac.len());
// When devices list change I need to update the wireless strength changes
let mut strength_changes = Vec::with_capacity(wireless_ac.len());

for ac in wireless_ac.iter() {
let ssid = ac.ssid.clone();

let dp = DeviceProxy::builder(conn)
.path(ac.device_path.clone())?
.build()
Expand All @@ -406,28 +413,26 @@ impl NetworkService {
device_state_changes.push(
dp.receive_state_changed()
.await
.filter_map(|val| async move {
let val = val.get().await;
let val = val.map(DeviceState::from).unwrap_or_default();

if val == DeviceState::NeedAuth {
Some(val)
} else {
None
.filter_map({
let ssid = ssid.clone();
move |val| {
let ssid = ssid.clone();
async move {
let val = val.get().await;
let val = val.map(DeviceState::from).unwrap_or_default();

if val == DeviceState::NeedAuth {
debug!("Request password for ssid {}", ssid);
Some(NetworkEvent::RequestPasswordForSSID(ssid))
} else {
None
}
}
}
})
.map(|_| {
let ssid = ac.ssid.clone();

debug!("Request password for ssid {}", ssid);
NetworkEvent::RequestPasswordForSSID(ssid)
}),
.boxed(),
);
}

// When devices list change I need to update the access points changes
let mut ac_changes = Vec::with_capacity(wireless_ac.len());
for ac in wireless_ac.iter() {
let dp = WirelessDeviceProxy::builder(conn)
.path(ac.device_path.clone())?
.build()
Expand All @@ -452,14 +457,9 @@ impl NetworkService {
})
.boxed(),
);
}

// When devices list change I need to update the wireless strength changes
let mut strength_changes = Vec::with_capacity(wireless_ac.len());
for ap in wireless_ac {
let ssid = ap.ssid.clone();
let app = AccessPointProxy::builder(conn)
.path(ap.path.clone())?
.path(ac.path.clone())?
.build()
.await?;

Expand All @@ -477,7 +477,6 @@ impl NetworkService {
.boxed(),
);
}
let strength_changes = select_all(strength_changes).boxed();

let access_points = select_all(ac_changes).boxed();

Expand Down Expand Up @@ -511,8 +510,9 @@ impl NetworkService {
connectivity_changed,
active_connections_changes,
access_points,
strength_changes,
select_all(strength_changes).boxed(),
known_connections,
select_all(device_state_changes).boxed(),
]);

Ok(events)
Expand Down
Loading