don't panic on keyring fail + disable button while connecting
This commit is contained in:
@@ -29,11 +29,10 @@ impl ClientData {
|
||||
self.data.load::<AccountList>().push(info);
|
||||
}
|
||||
|
||||
pub fn password(&self, info: &AccountInfo) -> String {
|
||||
pub fn password(&self, info: &AccountInfo) -> Result<String, String> {
|
||||
let user_path = info.path();
|
||||
let entry =
|
||||
keyring_core::Entry::new("openworm", &user_path).expect("failed to open keyring entry");
|
||||
entry.get_password().unwrap()
|
||||
let entry = keyring_core::Entry::new("openworm", &user_path).map_err(|e| e.to_string())?;
|
||||
entry.get_password().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
pub fn accounts(&self) -> DataGuard<AccountList> {
|
||||
|
||||
@@ -31,8 +31,7 @@ pub fn start(rsc: &mut Rsc, data: &ClientData) -> WeakWidget {
|
||||
.add(rsc),
|
||||
color::DARK,
|
||||
rsc,
|
||||
)
|
||||
.add(rsc);
|
||||
);
|
||||
let account = account.clone();
|
||||
let cert_hex = data
|
||||
.data
|
||||
@@ -44,14 +43,22 @@ pub fn start(rsc: &mut Rsc, data: &ClientData) -> WeakWidget {
|
||||
let cert = decode_hex(&cert_hex).unwrap();
|
||||
keyring::use_native_store(true).unwrap();
|
||||
rsc.events.register(button, Submit, move |ctx, rsc| {
|
||||
let password = match ctx.state.data.password(&account) {
|
||||
Ok(v) => v,
|
||||
Err(err) => {
|
||||
ctx.state.error(&err, rsc);
|
||||
return;
|
||||
}
|
||||
};
|
||||
button.disable(rsc);
|
||||
let account = account.clone();
|
||||
let cert = cert.clone();
|
||||
let password = ctx.state.data.password(&account);
|
||||
let event_sender = rsc.window_event.clone();
|
||||
rsc.spawn_task(async move |mut ctx| {
|
||||
let mut fail = |reason: &str| {
|
||||
let reason = reason.to_string();
|
||||
ctx.update(move |ctx, rsc| {
|
||||
button.enable(rsc);
|
||||
ctx.error(&reason, rsc);
|
||||
})
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user