remove some unwraps

This commit is contained in:
Erica Z 2024-11-02 11:18:33 +01:00
parent a027922b0e
commit 055df38c32

View file

@ -127,27 +127,30 @@ mod imp {
} }
async fn save(&self) { async fn save(&self) {
assert!(self.obj().authn_can_edit());
self.obj().set_authn_can_edit(false); self.obj().set_authn_can_edit(false);
// TODO remove unwraps etc etc async fn wrapper(self_: &Setup) -> Result<(), impl std::error::Error> {
let keyring = oo7::Keyring::new().await.unwrap(); let keyring = oo7::Keyring::new().await?;
let mut attributes = vec![("xdg:schema", crate::APP_ID.to_string())]; let mut attributes = vec![("xdg:schema", crate::APP_ID.to_string())];
// clear previous passwords // clear previous passwords
keyring.delete(&attributes).await.unwrap(); keyring.delete(&attributes).await?;
attributes.push(("server-url", self.obj().server_url())); attributes.push(("server-url", self_.obj().server_url()));
attributes.push(("username", self.obj().username())); attributes.push(("username", self_.obj().username()));
keyring keyring
.create_item( .create_item(
"Audrey Subsonic password", "Audrey Subsonic password",
&attributes, &attributes,
self.obj().password(), self_.obj().password(),
true, true,
) )
.await .await
.unwrap(); }
let result = wrapper(self).await;
self.obj().set_authn_can_edit(true); self.obj().set_authn_can_edit(true);
result.unwrap(); // FIXME
} }
} }
} }
@ -167,6 +170,7 @@ impl Setup {
#[weak(rename_to = self_)] #[weak(rename_to = self_)]
self, self,
async move { async move {
assert!(self_.authn_can_edit())
self_.set_authn_can_edit(false); self_.set_authn_can_edit(false);
// TODO remove unwraps, make sure authn_can_edit is set back to true // TODO remove unwraps, make sure authn_can_edit is set back to true