avoid single variant match statements

This commit is contained in:
daniel.eades 2023-11-16 18:07:40 +00:00 • committed by Ashley Wulber
parent 7239d6dfd6
commit fed18d3726
2 changed files with 28 additions and 38 deletions

View file

@ -289,18 +289,15 @@ impl cosmic::Application for CosmicNetworkApplet {
} }
} }
if !success { if !success {
match req { if let NetworkManagerRequest::Password(_, _) = req {
NetworkManagerRequest::Password(_, _) => { if let Some(
if let Some( NewConnectionState::EnterPassword { access_point, .. }
NewConnectionState::EnterPassword { access_point, .. } | NewConnectionState::Waiting(access_point),
| NewConnectionState::Waiting(access_point), ) = self.new_connection.as_ref()
) = self.new_connection.as_ref() {
{ self.new_connection
self.new_connection .replace(NewConnectionState::Failure(access_point.clone()));
.replace(NewConnectionState::Failure(access_point.clone()));
}
} }
_ => {}
} }
} }
self.update_nm_state(state); self.update_nm_state(state);
@ -327,12 +324,13 @@ impl cosmic::Application for CosmicNetworkApplet {
self.new_connection.take(); self.new_connection.take();
self.show_visible_networks = !self.show_visible_networks; self.show_visible_networks = !self.show_visible_networks;
} }
Message::Password(entered_pw) => match &mut self.new_connection { Message::Password(entered_pw) => {
Some(NewConnectionState::EnterPassword { password, .. }) => { if let Some(NewConnectionState::EnterPassword { password, .. }) =
&mut self.new_connection
{
*password = entered_pw; *password = entered_pw;
} }
_ => {} }
},
Message::SubmitPassword => { Message::SubmitPassword => {
// save password // save password
let tx = if let Some(tx) = self.nm_sender.as_ref() { let tx = if let Some(tx) = self.nm_sender.as_ref() {
@ -341,19 +339,17 @@ impl cosmic::Application for CosmicNetworkApplet {
return Command::none(); return Command::none();
}; };
match self.new_connection.take() { if let Some(NewConnectionState::EnterPassword {
Some(NewConnectionState::EnterPassword { password,
password, access_point,
access_point, }) = self.new_connection.take()
}) => { {
let _ = tx.unbounded_send(NetworkManagerRequest::Password( let _ = tx.unbounded_send(NetworkManagerRequest::Password(
access_point.ssid.clone(), access_point.ssid.clone(),
password.to_string(), password.to_string(),
)); ));
self.new_connection self.new_connection
.replace(NewConnectionState::Waiting(access_point.clone())); .replace(NewConnectionState::Waiting(access_point.clone()));
}
_ => {}
}; };
} }
Message::ActivateKnownWifi(ssid) => { Message::ActivateKnownWifi(ssid) => {
@ -383,11 +379,8 @@ impl cosmic::Application for CosmicNetworkApplet {
.iter_mut() .iter_mut()
.find(|c| c.name() == ssid) .find(|c| c.name() == ssid)
{ {
match ap { if let ActiveConnectionInfo::WiFi { state, .. } = ap {
ActiveConnectionInfo::WiFi { state, .. } => { *state = ActiveConnectionState::Deactivating;
*state = ActiveConnectionState::Deactivating;
}
_ => {}
} }
} }
tx tx

View file

@ -90,11 +90,8 @@ pub async fn create_service(connection: &zbus::Connection) -> zbus::Result<()> {
let mut name_owner_changed_stream = dbus_proxy.receive_name_owner_changed().await?; let mut name_owner_changed_stream = dbus_proxy.receive_name_owner_changed().await?;
let flags = RequestNameFlags::AllowReplacement.into(); let flags = RequestNameFlags::AllowReplacement.into();
match dbus_proxy.request_name(NAME.as_ref(), flags).await? { if dbus_proxy.request_name(NAME.as_ref(), flags).await? == RequestNameReply::InQueue {
RequestNameReply::InQueue => { eprintln!("Bus name '{}' already owned", NAME);
eprintln!("Bus name '{}' already owned", NAME);
}
_ => {}
} }
let connection = connection.clone(); let connection = connection.clone();