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