Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Settings: the update card stops asking for a frame at the display's rate

小睦707cfb9a6107
diff --git a/crates/rf-app/src/settings_view.rs b/crates/rf-app/src/settings_view.rs
index d8e945bf..57eb788a 100644
--- a/crates/rf-app/src/settings_view.rs
+++ b/crates/rf-app/src/settings_view.rs
@@ -4466,11 +4466,7 @@ fn update_card(p: &Palette, s: &Settings) -> AnyElement {
State::Checking => Some(
glow(tint, 0.22)
.w(relative(0.3))
- .with_animation(
- "upd-sweep",
- Animation::new(std::time::Duration::from_millis(1200)).repeat().with_easing(ease_in_out),
- |el, t| el.left(relative(-0.3 + 1.3 * t)),
- )
+ .left(relative(-0.3 + 1.3 * sweep(1200)))
.into_any_element(),
),
State::Downloading(_, pct) => Some(
@@ -4484,13 +4480,7 @@ fn update_card(p: &Palette, s: &Settings) -> AnyElement {
.bg(tint.opacity(0.18))
.child(
// a soft highlight running along the filled part
- glow(tint, 0.2)
- .w(px(120.))
- .with_animation(
- "upd-run",
- Animation::new(std::time::Duration::from_millis(1000)).repeat(),
- |el, t| el.left(relative(-0.2 + 1.2 * t)),
- ),
+ glow(tint, 0.2).w(px(120.)).left(relative(-0.2 + 1.2 * sweep(1000))),
)
.into_any_element(),
),
@@ -4514,6 +4504,23 @@ fn glow(c: Hsla, alpha: f32) -> Div {
div().absolute().top_0().bottom_0().flex().child(half(0., alpha)).child(half(alpha, 0.))
}
+/// How far a band of light has travelled (0..1) after `period` milliseconds, read when the card is drawn.
+///
+/// WHY NOT `with_animation(..).repeat()`: a repeating animation asks for a frame at the display's rate for as long as it runs, so
+/// checking for or downloading an update kept a whole core busy (about 50 % here). The card is redrawn a few times a second
+/// meanwhile (`installer::redraw_while_busy`), so the light still moves, at that rate, for next to nothing.
+fn sweep(period_ms: u64) -> f32 {
+ let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_millis());
+ let t = (now % u128::from(period_ms)) as f32 / period_ms as f32;
+ // ease in and out, as the animation did
+ if t < 0.5 {
+ 2.0 * t * t
+ } else {
+ let x = -2.0 * t + 2.0;
+ 1.0 - x * x / 2.0
+ }
+}
+
/// "Check for updates": runs off the UI thread and redraws while it checks, and downloads what it finds only while "Download
/// updates automatically" is on (off: the card offers a Download button, `installer::check`).
pub(crate) fn check_updates_now(cx: &mut App) {