Improve TUI OTP readability
This commit is contained in:
@@ -138,6 +138,9 @@ impl OtpDisplay {
|
||||
pub fn counter(&self) -> Option<u64> {
|
||||
self.validity.counter()
|
||||
}
|
||||
pub fn period_seconds(&self) -> Option<u64> {
|
||||
self.validity.period()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
@@ -542,19 +545,33 @@ impl App {
|
||||
return None;
|
||||
}
|
||||
let viewer = self.viewer.as_ref()?;
|
||||
let field = viewer.focused_field()?;
|
||||
let otp = field.metadata().otp()?;
|
||||
if otp.kind() != ironstorage::otp::OtpKind::Totp {
|
||||
return None;
|
||||
}
|
||||
let entry = self.selected_entry.clone()?;
|
||||
if self.otp_display.as_ref().is_some_and(|display| {
|
||||
display.entry == entry
|
||||
&& display.field == Some(field.id())
|
||||
&& display.remaining_seconds != Some(0)
|
||||
}) {
|
||||
return None;
|
||||
}
|
||||
let field = if let Some(display) = self
|
||||
.otp_display
|
||||
.as_ref()
|
||||
.filter(|display| display.entry == entry)
|
||||
{
|
||||
match display.remaining_seconds {
|
||||
Some(0) => {
|
||||
let field_id = display.field?;
|
||||
viewer.document().fields().iter().find(|field| {
|
||||
field.id() == field_id
|
||||
&& field
|
||||
.metadata()
|
||||
.otp()
|
||||
.is_some_and(|otp| otp.kind() == ironstorage::otp::OtpKind::Totp)
|
||||
})?
|
||||
}
|
||||
Some(_) | None => return None,
|
||||
}
|
||||
} else {
|
||||
viewer.document().fields().iter().find(|field| {
|
||||
field
|
||||
.metadata()
|
||||
.otp()
|
||||
.is_some_and(|otp| otp.kind() == ironstorage::otp::OtpKind::Totp)
|
||||
})?
|
||||
};
|
||||
self.otp_pending = true;
|
||||
Some((entry, field.id()))
|
||||
}
|
||||
@@ -998,13 +1015,11 @@ impl App {
|
||||
Action::FocusNext if self.mode == Mode::Viewer => {
|
||||
if let Some(viewer) = self.viewer.as_mut() {
|
||||
viewer.focus_next();
|
||||
self.otp_display = None;
|
||||
}
|
||||
}
|
||||
Action::FocusPrevious if self.mode == Mode::Viewer => {
|
||||
if let Some(viewer) = self.viewer.as_mut() {
|
||||
viewer.focus_previous();
|
||||
self.otp_display = None;
|
||||
}
|
||||
}
|
||||
Action::FocusNext if self.mode == Mode::Editor => {
|
||||
|
||||
Reference in New Issue
Block a user