pub async fn connect_to(
        &self,
        ssid: SSID,
        credentials: AccessPointCredentials,
        hw: Option<String>,
        overwrite_same_ssid_connection: bool,
    ) -> Result<Option<ActiveConnection>, CaptivePortalError> {
        // try to find connection, update it, activate it and return the connection path
        let active_connection = if let Some(hw) = hw {
            if let Some((connection_path, old_connection)) = self.find_connection_by_mac(&hw).await? {
                Some(
                    self.update_connection(connection_path, &ssid, old_connection, credentials.clone())
                        .await?,
                )
            } else {
                None
            }
        } else if overwrite_same_ssid_connection {
            if let Some((connection_path, old_connection)) = self.find_connection_by_ssid(&ssid).await? {
                Some(
                    self.update_connection(connection_path, &ssid, old_connection, credentials.clone())
                        .await?,
                )
            } else {
                None
            }
        } else {
            None
        };

        // If not found: Create and activate a new connection
        let (connection_path, active_connection) = if let Some(active_connection) = active_connection {
            active_connection
        } else {
            let settings = wifi_settings::make_arguments_for_ap(&ssid, credentials, None)?;
            let options = wifi_settings::make_options_for_ap();

            // Create connection
            use networkmanager::NetworkManager;
            let p = nonblock::Proxy::new(NM_BUSNAME, NM_PATH, self.conn.clone());
            let (conn_path, active_connection, _) = p
                .add_and_activate_connection2(settings, self.wifi_device_path.clone(), "/".into(), options)
                .await?;
            (conn_path, active_connection)
        };

        // Wait up to 5 seconds while in Deactivated
        let state = self
            .wait_for_active_connection_state(
                ConnectionState::Deactivated,
                active_connection.clone(),
                Duration::from_secs(10),
                true,
            )
            .await?;
        // Not successful
        if state == ConnectionState::Deactivated {
            use connection_nm::Connection;
            let p = nonblock::Proxy::new(NM_BUSNAME, connection_path, self.conn.clone());
            p.delete().await?;
            return Ok(None);
        }

        // Wait up to 30 seconds while in Activating
        let state = self
            .wait_for_active_connection_state(
                ConnectionState::Activated,
                active_connection.clone(),
                Duration::from_secs(30),
                false,
            )
            .await?;

        // Remove connection if not successful. Store it permanently if successful
        if state == ConnectionState::Activated {
            use connection_nm::Connection;
            let p = nonblock::Proxy::new(NM_BUSNAME, connection_path.clone(), self.conn.clone());

            // Settings: Provide an empty array, to use the current settings.
            p.update2(VariantMapNested::new(), SAVE_TO_DISK_FLAG, VariantMap::new())
                .await?;
            return Ok(Some(ActiveConnection {
                connection_path: connection_path.into_static(),
                active_connection_path: active_connection.into_static(),
                state,
            }));
        } else {
            use connection_nm::Connection;
            let p = nonblock::Proxy::new(NM_BUSNAME, connection_path, self.conn.clone());
            p.delete().await?;
            return Ok(None);
        }
    }
/// Connect to the given SSID with the given credentials.
/// First tries to find a wifi connection if "hw" is set or "overwrite_same_ssid_connection" is true.
/// If it finds one, the connection will be altered to use the given credentials and SSID, otherwise a new connection is created.
///
/// If "overwrite_same_ssid_connection" is false and "hw" is not set, but network manager already knows about a connection
/// to a SSID with the same name, it will add a number suffix to the connection name. If the SSID is
/// for example "My AP" and there is already a connection with the name "My AP", the newly
/// created connection will be named "My AP 1".
///
/// # Arguments:
/// * ssid: The ssid
/// * credentials: The connection credentials
/// * hw: The target access point mac address. If this is set, this method will first try to find
///   a connection that was connected to that access point in the past and update that connection.
/// * overwrite_same_ssid_connection: If this is true and a connection can be found that matches the
///   given SSID, that connection will be updated.
Connect to the given SSID with the given credentials.
First tries to find a wifi connection if "hw" is set or "overwrite_same_ssid_connection" is true.
If it finds one, the connection will be altered to use the given credentials and SSID, otherwise a new connection is created.

If "overwrite_same_ssid_connection" is false and "hw" is not set, but network manager already knows about a connection
to a SSID with the same name, it will add a number suffix to the connection name.
Connect to the given SSID with the given credentials . First tries to find a wifi connection if " hw " is set or " overwrite_same_ssid_connection " is true . If it finds one the connection will be altered to use the given credentials and SSID otherwise a new connection is created . If " overwrite_same_ssid_connection " is false and " hw " is not set but network manager already knows about a connection to a SSID with the same name it will add a number suffix to the connection name .
pub async fn connect_to(
        &self,
        ssid: SSID,
        credentials: AccessPointCredentials,
        hw: Option<String>,
        overwrite_same_ssid_connection: bool,
    ) -> Result<Option<ActiveConnection>, CaptivePortalError> {
        // try to find connection, update it, activate it and return the connection path
        let active_connection = if let Some(hw) = hw {
            if let Some((connection_path, old_connection)) = self.find_connection_by_mac(&hw).await? {
                Some(
                    self.update_connection(connection_path, &ssid, old_connection, credentials.clone())
                        .await?,
                )
            } else {
                None
            }
        } else if overwrite_same_ssid_connection {
            if let Some((connection_path, old_connection)) = self.find_connection_by_ssid(&ssid).await? {
                Some(
                    self.update_connection(connection_path, &ssid, old_connection, credentials.clone())
                        .await?,
                )
            } else {
                None
            }
        } else {
            None
        };
        // If not found: Create and activate a new connection
        let (connection_path, active_connection) = if let Some(active_connection) = active_connection {
            active_connection
        } else {
            let settings = wifi_settings::make_arguments_for_ap(&ssid, credentials, None)?;
            let options = wifi_settings::make_options_for_ap();
            // Create connection
            use networkmanager::NetworkManager;
            let p = nonblock::Proxy::new(NM_BUSNAME, NM_PATH, self.conn.clone());
            let (conn_path, active_connection, _) = p
                .add_and_activate_connection2(settings, self.wifi_device_path.clone(), "/".into(), options)
                .await?;
            (conn_path, active_connection)
        };
        // Wait up to 5 seconds while in Deactivated
        let state = self
            .wait_for_active_connection_state(
                ConnectionState::Deactivated,
                active_connection.clone(),
                Duration::from_secs(10),
                true,
            )
            .await?;
        // Not successful
        if state == ConnectionState::Deactivated {
            use connection_nm::Connection;
            let p = nonblock::Proxy::new(NM_BUSNAME, connection_path, self.conn.clone());
            p.delete().await?;
            return Ok(None);
        }
        // Wait up to 30 seconds while in Activating
        let state = self
            .wait_for_active_connection_state(
                ConnectionState::Activated,
                active_connection.clone(),
                Duration::from_secs(30),
                false,
            )
            .await?;
        // Remove connection if not successful. Store it permanently if successful
        if state == ConnectionState::Activated {
            use connection_nm::Connection;
            let p = nonblock::Proxy::new(NM_BUSNAME, connection_path.clone(), self.conn.clone());
            // Settings: Provide an empty array, to use the current settings.
            p.update2(VariantMapNested::new(), SAVE_TO_DISK_FLAG, VariantMap::new())
                .await?;
            return Ok(Some(ActiveConnection {
                connection_path: connection_path.into_static(),
                active_connection_path: active_connection.into_static(),
                state,
            }));
        } else {
            use connection_nm::Connection;
            let p = nonblock::Proxy::new(NM_BUSNAME, connection_path, self.conn.clone());
            p.delete().await?;
            return Ok(None);
        }
    }
pub async fn connect_to ( & self , ssid : SSID , credentials : AccessPointCredentials , hw : Option < String > , overwrite_same_ssid_connection : bool , ) -> Result < Option < ActiveConnection > , CaptivePortalError > { // try to find connection, update it, activate it and return the connection path let active_connection = if let Some ( hw ) = hw { if let Some ( ( connection_path , old_connection ) ) = self . find_connection_by_mac ( & hw ) . await ? { Some ( self . update_connection ( connection_path , & ssid , old_connection , credentials . clone ( ) ) . await ? , ) } else { None } } else if overwrite_same_ssid_connection { if let Some ( ( connection_path , old_connection ) ) = self . find_connection_by_ssid ( & ssid ) . await ? { Some ( self . update_connection ( connection_path , & ssid , old_connection , credentials . clone ( ) ) . await ? , ) } else { None } } else { None } ; // If not found: Create and activate a new connection let ( connection_path , active_connection ) = if let Some ( active_connection ) = active_connection { active_connection } else { let settings = wifi_settings :: make_arguments_for_ap ( & ssid , credentials , None ) ? ; let options = wifi_settings :: make_options_for_ap ( ) ; // Create connection use networkmanager :: NetworkManager ; let p = nonblock :: Proxy :: new ( NM_BUSNAME , NM_PATH , self . conn . clone ( ) ) ; let ( conn_path , active_connection , _ ) = p . add_and_activate_connection2 ( settings , self . wifi_device_path . clone ( ) , " " . into ( ) , options ) . await ? ; ( conn_path , active_connection ) } ; // Wait up to 5 seconds while in Deactivated let state = self . wait_for_active_connection_state ( ConnectionState :: Deactivated , active_connection . clone ( ) , Duration :: from_secs ( 10 ) , true , ) . await ? ; // Not successful if state == ConnectionState :: Deactivated { use connection_nm :: Connection ; let p = nonblock :: Proxy :: new ( NM_BUSNAME , connection_path , self . conn . clone ( ) ) ; p . delete ( ) . await ? ; return Ok ( None ) ; } // Wait up to 30 seconds while in Activating let state = self . wait_for_active_connection_state ( ConnectionState :: Activated , active_connection . clone ( ) , Duration :: from_secs ( 30 ) , false , ) . await ? ; // Remove connection if not successful. Store it permanently if successful if state == ConnectionState :: Activated { use connection_nm :: Connection ; let p = nonblock :: Proxy :: new ( NM_BUSNAME , connection_path . clone ( ) , self . conn . clone ( ) ) ; // Settings: Provide an empty array, to use the current settings. p . update2 ( VariantMapNested :: new ( ) , SAVE_TO_DISK_FLAG , VariantMap :: new ( ) ) . await ? ; return Ok ( Some ( ActiveConnection { connection_path : connection_path . into_static ( ) , active_connection_path : active_connection . into_static ( ) , state , } ) ) ; } else { use connection_nm :: Connection ; let p = nonblock :: Proxy :: new ( NM_BUSNAME , connection_path , self . conn . clone ( ) ) ; p . delete ( ) . await ? ; return Ok ( None ) ; } }
Connect to the given SSID with the given credentials.
Connect to the given SSID with the given credentials .
&self
ssid
SSID
credentials
AccessPointCredentials
hw
Option<String>
overwrite_same_ssid_connection
bool
&self
ssid
SSID
credentials
AccessPointCredentials
hw
Option<String>
overwrite_same_ssid_connection
bool
arguments:
The ssid
credentials: The connection credentials
hw: The target access point mac address. If this is set, this method will first try to find
a connection that was connected to that access point in the past and update that connection.
overwrite_same_ssid_connection: If this is true and a connection can be found that matches the
given SSID, that connection will be updated.
The ssid credentials : The connection credentials hw : The target access point mac address . If this is set this method will first try to find a connection that was connected to that access point in the past and update that connection . overwrite_same_ssid_connection : If this is true and a connection can be found that matches the given SSID that connection will be updated .