From 055df38c3232f0a1022a4f5029a855a0c2e048aa Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sat, 2 Nov 2024 11:18:33 +0100 Subject: [PATCH] remove some unwraps --- src/ui/setup.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/ui/setup.rs b/src/ui/setup.rs index 71662a7..b4df05b 100644 --- a/src/ui/setup.rs +++ b/src/ui/setup.rs @@ -127,27 +127,30 @@ mod imp { } async fn save(&self) { + assert!(self.obj().authn_can_edit()); self.obj().set_authn_can_edit(false); - // TODO remove unwraps etc etc - let keyring = oo7::Keyring::new().await.unwrap(); - let mut attributes = vec![("xdg:schema", crate::APP_ID.to_string())]; - // clear previous passwords - keyring.delete(&attributes).await.unwrap(); + async fn wrapper(self_: &Setup) -> Result<(), impl std::error::Error> { + let keyring = oo7::Keyring::new().await?; + let mut attributes = vec![("xdg:schema", crate::APP_ID.to_string())]; + // clear previous passwords + keyring.delete(&attributes).await?; - attributes.push(("server-url", self.obj().server_url())); - attributes.push(("username", self.obj().username())); - keyring - .create_item( - "Audrey Subsonic password", - &attributes, - self.obj().password(), - true, - ) - .await - .unwrap(); + attributes.push(("server-url", self_.obj().server_url())); + attributes.push(("username", self_.obj().username())); + keyring + .create_item( + "Audrey Subsonic password", + &attributes, + self_.obj().password(), + true, + ) + .await + } + let result = wrapper(self).await; self.obj().set_authn_can_edit(true); + result.unwrap(); // FIXME } } } @@ -167,6 +170,7 @@ impl Setup { #[weak(rename_to = self_)] self, async move { + assert!(self_.authn_can_edit()) self_.set_authn_can_edit(false); // TODO remove unwraps, make sure authn_can_edit is set back to true