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) {
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();
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.unwrap();
keyring.delete(&attributes).await?;
attributes.push(("server-url", self.obj().server_url()));
attributes.push(("username", self.obj().username()));
attributes.push(("server-url", self_.obj().server_url()));
attributes.push(("username", self_.obj().username()));
keyring
.create_item(
"Audrey Subsonic password",
&attributes,
self.obj().password(),
self_.obj().password(),
true,
)
.await
.unwrap();
}
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