feat: use activate-connection2 on wifi login

This commit is contained in:
imgurbot12 2023-08-19 23:47:00 -07:00
parent b13f3cc9ce
commit 5fb383851c

View File

@ -1,5 +1,3 @@
use glib::translate::FromGlib;
use async_std::task; use async_std::task;
use futures_channel::oneshot; use futures_channel::oneshot;
use std::cell::RefCell; use std::cell::RefCell;
@ -8,6 +6,9 @@ use std::rc::Rc;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use glib::translate::FromGlib;
use glib::Variant;
use nm::traits::ObjectExt;
use nm::*; use nm::*;
static SCAN_INTERVAL_MS: u64 = 500; static SCAN_INTERVAL_MS: u64 = 500;
@ -32,6 +33,7 @@ pub struct AccessPoint {
pub security: String, pub security: String,
pub is_active: bool, pub is_active: bool,
pub connection: Option<Connection>, pub connection: Option<Connection>,
pub dbus_path: Option<String>,
} }
// SETTING_WIRELESS_MODE // SETTING_WIRELESS_MODE
@ -226,6 +228,7 @@ impl Manager {
let active = self.wifi.active_access_point(); let active = self.wifi.active_access_point();
for a in self.wifi.access_points() { for a in self.wifi.access_points() {
// retrieve access-point information // retrieve access-point information
let path = a.path();
let rate = a.max_bitrate() / 1000; let rate = a.max_bitrate() / 1000;
let signal = a.strength(); let signal = a.strength();
let ssid = a let ssid = a
@ -271,6 +274,7 @@ impl Manager {
is_active, is_active,
security: security.join(" ").to_owned(), security: security.join(" ").to_owned(),
connection: a.filter_connections(&conns).get(0).cloned(), connection: a.filter_connections(&conns).get(0).cloned(),
dbus_path: path.map(|s| s.to_string()),
}, },
); );
} }
@ -295,10 +299,21 @@ impl Manager {
wait_conn(&active_conn, self.timeout).await?; wait_conn(&active_conn, self.timeout).await?;
} }
None => { None => {
// generate options
let mut options: BTreeMap<String, Variant> = BTreeMap::new();
options.insert("persist".to_string(), "disk".to_variant());
options.insert("bind-activation".to_string(), "none".to_variant());
// complete connection
let glib_opts = options.to_variant();
let conn = new_conn(ap, password)?; let conn = new_conn(ap, password)?;
let active_conn = self let (active_conn, _) = self
.client .client
.add_and_activate_connection_future(Some(&conn), Some(&device), None) .add_and_activate_connection2_future(
Some(&conn),
Some(&device),
ap.dbus_path.as_deref(),
&glib_opts,
)
.await .await
.context("Failed to add and activate connection")?; .context("Failed to add and activate connection")?;
wait_conn(&active_conn, self.timeout).await?; wait_conn(&active_conn, self.timeout).await?;