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.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
The bell's count stops re-reading a folder that only it keeps changing (824)
gelenmedya4601b1db5153
diff --git a/crates/rf-win/src/toasts/hint.rs b/crates/rf-win/src/toasts/hint.rsindex 0dc8fa37..90007a96 100644--- a/crates/rf-win/src/toasts/hint.rs+++ b/crates/rf-win/src/toasts/hint.rs@@ -118,10 +118,13 @@ pub fn start(callback: impl Fn(DotCount) + Send + 'static) -> Dot {Some(Msg::Hint) => timer.hint(Instant::now()),Some(Msg::Pause(p)) => timer.set_paused(p, Instant::now()),None => {- timer.read_done();+ let before = last;if let Some(c) = read(&mut last_read) {tell(c, &mut last);}+ if timer.read_done(last != before) {+ log::info!("notifications: the folder keeps changing but the count does not; the dot's reads slow down to one a minute (issue 824)");+ }}}}diff --git a/crates/rf-win/src/toasts/mod.rs b/crates/rf-win/src/toasts/mod.rsindex 46b103d4..7b00c628 100644--- a/crates/rf-win/src/toasts/mod.rs+++ b/crates/rf-win/src/toasts/mod.rs@@ -428,12 +428,19 @@ impl RemoveWatch {pub const HINT_MIN_GAP: Duration = Duration::from_secs(3);pub const HINT_SETTLE: Duration = Duration::from_millis(800);pub const HINT_BURST_CAP: Duration = Duration::from_secs(3);+/// The longest gap the reads slow down to while the folder keeps changing and the count does not (see [`HintTimer::read_done`]).+pub const HINT_MAX_GAP: Duration = Duration::from_secs(60);/// When the read of a burst of changes is made: [`HINT_SETTLE`] after the last change, but not later than [`HINT_BURST_CAP`] after the/// first one, and never before [`HINT_MIN_GAP`] has passed since the last read. The last rule wins over the other two, so a burst/// that comes soon after a read can never make two reads closer than the gap.pub fn read_at(last_read: Option<Instant>, first_hint: Instant, last_hint: Instant) -> Instant {- let earliest = last_read.map_or(first_hint, |t| t + HINT_MIN_GAP);+ read_after_gap(HINT_MIN_GAP, last_read, first_hint, last_hint)+}++/// [`read_at`] with a gap of its own between two reads.+fn read_after_gap(gap: Duration, last_read: Option<Instant>, first_hint: Instant, last_hint: Instant) -> Instant {+ let earliest = last_read.map_or(first_hint, |t| t + gap);(last_hint + HINT_SETTLE).min(first_hint + HINT_BURST_CAP).max(earliest)}@@ -444,6 +451,8 @@ pub struct HintTimer {burst: Option<(Instant, Instant)>,/// The bell's panel is open: it reads the list itself, so the folder's changes are not read a second time.paused: bool,+ /// Reads in a row, each made for a change in the folder, that found the count it had before.+ idle_reads: u32,}impl HintTimer {@@ -468,18 +477,39 @@ impl HintTimer {if paused {self.burst = None;} else {+ self.idle_reads = 0;self.hint(now);}}/// When to read, or `None` when nothing is waiting.pub fn due(&self, last_read: Option<Instant>) -> Option<Instant> {- self.burst.map(|(first, last)| read_at(last_read, first, last))+ self.burst.map(|(first, last)| read_after_gap(self.gap(), last_read, first, last))+ }++ /// The shortest time between two reads now: [`HINT_MIN_GAP`], doubled for each read in a row that found nothing new, up to+ /// [`HINT_MAX_GAP`].+ pub fn gap(&self) -> Duration {+ (HINT_MIN_GAP * 2u32.pow(self.idle_reads.min(5))).min(HINT_MAX_GAP)}- /// The read was made.- pub fn read_done(&mut self) {+ /// The read was made; `changed`: it found another count than the read before. True when this read made the reads slow down+ /// for the first time (for one line in the log).+ ///+ /// WHY (issue 824: with rustyfiles' panel on and notifications in the list, Windows' notification service wrote up to 100 MB/s+ /// on one machine, build 26300, and stopped when the panel was switched off). The read for the dot is made because the folder of+ /// the notification database changed. On that machine the service seems to write to the folder when the list is read, so each+ /// read set off the next one, every 3 s, for ever. On this PC, the same build, a read writes nothing, so it could not be seen+ /// here. A folder that keeps changing while the count stays the same now slows the reads down to one a minute; a new count, or+ /// the panel closing, brings them back to every 3 s.+ pub fn read_done(&mut self, changed: bool) -> bool {self.burst = None;+ if changed {+ self.idle_reads = 0;+ return false;+ }+ self.idle_reads = self.idle_reads.saturating_add(1);+ self.idle_reads == 3}}@@ -770,10 +800,33 @@ mod tests {t.hint(at(b, ms));assert!(t.due(Some(b)).unwrap() >= at(b, 3_000), "hint at {ms} ms");}- t.read_done();+ t.read_done(true);assert_eq!(t.due(Some(b)), None, "nothing waits after the read");}+ /// Issue 824: a folder that changes after every read (the read itself making Windows write there) slows the reads down to one a+ /// minute instead of one every 3 s for ever; a new count brings the 3 s back.+ #[test]+ fn a_folder_that_keeps_changing_while_the_count_stays_slows_the_reads_down() {+ let b = Instant::now();+ let mut t = HintTimer::default();+ assert_eq!(t.gap(), HINT_MIN_GAP);+ let mut warned = 0;+ for _ in 0..10 {+ warned += t.read_done(false) as u32;+ }+ assert_eq!(warned, 1, "said once");+ assert_eq!(t.gap(), HINT_MAX_GAP);+ t.hint(at(b, 1_000));+ assert_eq!(t.due(Some(b)), Some(at(b, 60_000)), "a minute after the last read");+ assert!(!t.read_done(true));+ assert_eq!(t.gap(), HINT_MIN_GAP, "a new count: every 3 s again");+ t.read_done(false);+ t.set_paused(true, at(b, 2_000));+ t.set_paused(false, at(b, 3_000));+ assert_eq!(t.gap(), HINT_MIN_GAP, "the panel closing: every 3 s again");+ }+#[test]fn the_hint_timer_is_silent_while_the_panel_is_open_and_reads_once_when_it_closes() {let b = Instant::now();