refactor(core): use a one-shot timer for the eye hint start delay
What changed, and why it matters
This is a user-interface performance cleanup. It changes how a small eye icon (hinting that a hidden passphrase can be shown) waits before sliding onto the screen. Previously the screen was redrawn on every animation frame during the short pause; now a one-shot timer waits and only then starts the animation. There is no security-relevant change here.
No security action needed. Treat as a normal UI refactor/performance improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors EyeHintAnimation in the Trezor firmware Rust UI. It replaces an animation-frame-driven start delay with a one-shot Timer. The visible behavior is unchanged: a 200 ms pause before a slide-in animation. The code now stops the delay timer when visibility changes, starts the slide-in Stopwatch only after the delay expires, and adjusts progress() so it no longer subtracts START_DELAY. This is purely an optimization to reduce unnecessary repaints.
Changed components
core/embed/rust/src/ui/component/eye_hint.rsInspect captured patch +26 / −12
### core/embed/rust/src/ui/component/eye_hint.rs
@@ -1,20 +1,31 @@
use sys::time::Duration;
use crate::time::Stopwatch;
-use crate::ui::component::{Event, EventCtx};
+use crate::ui::component::{Event, EventCtx, Timer};
use crate::ui::util::animation_disabled;
/// Slide-in of the eye icon hinting that the hidden passphrase can be
/// revealed.
///
/// Once the first hidden character appears, the icon slides in from the left
/// while the hidden characters move right to make room for it.
-#[derive(Default)]
pub struct EyeHintAnimation {
+ /// One-shot timer for the pause before the slide-in.
+ delay: Timer,
timer: Stopwatch,
visible: bool,
}
+impl Default for EyeHintAnimation {
+ fn default() -> Self {
+ Self {
+ delay: Timer::new(),
+ timer: Stopwatch::new_stopped(),
+ visible: false,
+ }
+ }
+}
+
impl EyeHintAnimation {
/// Pause between the first character being hidden and the slide-in.
const START_DELAY: Duration = Duration::from_millis(200);
@@ -31,24 +42,27 @@ impl EyeHintAnimation {
return;
}
self.visible = visible;
+ self.delay.stop();
self.timer = Stopwatch::new_stopped();
if visible && !animation_disabled() {
- self.timer.start();
- ctx.request_anim_frame();
+ self.delay.start(ctx, Self::START_DELAY);
}
ctx.request_paint();
}
- /// Keep requesting animation frames while the slide-in runs. Returns
- /// `true` when the input should be repainted.
+ /// Start the slide-in once the pause is over and keep requesting animation
+ /// frames while it runs. Returns `true` when the input should be
+ /// repainted.
pub fn process(&mut self, ctx: &mut EventCtx, event: Event) -> bool {
+ if self.delay.expire(event) {
+ self.timer.start();
+ ctx.request_anim_frame();
+ return false;
+ }
if !matches!(event, Event::Timer(EventCtx::ANIM_FRAME_TIMER)) || !self.timer.is_running() {
return false;
}
- if self
- .timer
- .is_running_within(Self::START_DELAY.saturating_add(Self::DURATION))
- {
+ if self.timer.is_running_within(Self::DURATION) {
ctx.request_anim_frame();
} else {
self.timer = Stopwatch::new_stopped();
@@ -73,15 +87,15 @@ impl EyeHintAnimation {
}
fn progress(&self, delay: Duration) -> f32 {
- if !self.visible {
+ if !self.visible || self.delay.is_running() {
return 0.0;
}
if !self.timer.is_running() {
return 1.0;
}
let elapsed = self.timer.elapsed();
match (
- elapsed.checked_sub(Self::START_DELAY.saturating_add(delay)),
+ elapsed.checked_sub(delay),
Self::DURATION.checked_sub(delay),
) {
(Some(elapsed), Some(duration)) => (elapsed / duration).min(1.0),Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.