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.

A work area that held for 5 s is set again at once when taken back; only a fight backs off (888)

gelenmedya8cfeb1bd3e51
diff --git a/crates/rf-shellguard/src/tbmodel.rs b/crates/rf-shellguard/src/tbmodel.rs
index 3a7d8ee9..0831d4e3 100644
--- a/crates/rf-shellguard/src/tbmodel.rs
+++ b/crates/rf-shellguard/src/tbmodel.rs
@@ -318,6 +318,11 @@ pub fn originals_to_save(already: &[WorkAreaRec], changes: &[WorkChange]) -> Vec
/// recomputes now and then (a program starting, Steam did it twice within seconds) is set again within seconds; one that it keeps
/// taking back is answered at most once per `max_gap_ms` after a few tries, so the two never fight. A plain "once a minute" left
/// maximised windows under the dock for up to a minute after the second recompute (issues 883, 888).
+///
+/// A fight is Explorer taking the work area back right after it was set. One that held for [`HELD_MS`] was taken back by something
+/// new (the dock reloading after a setting, a click on an island, a program starting): that is answered at once and the pauses start
+/// over. Counting those as a fight let the pauses grow to a minute in ordinary use, and maximised windows stayed under the dock
+/// ("the work area was set too often lately", issue 888).
#[derive(Clone, Debug)]
pub struct Backoff {
first_gap_ms: u64,
@@ -326,15 +331,22 @@ pub struct Backoff {
last_allowed: Option<(u64, u64)>,
/// When anyone last asked, allowed or not: a fight that goes on keeps the pauses long.
last_asked: u64,
+ /// Someone asked since the last answer was allowed (the first ask after it tells how long that answer held).
+ asked_since_allow: bool,
}
+/// How long a work area must have held to make taking it back a new event rather than a fight (see [`Backoff`]).
+pub const HELD_MS: u64 = 5_000;
+
impl Backoff {
pub fn new(first_gap_ms: u64, max_gap_ms: u64) -> Backoff {
- Backoff { first_gap_ms, max_gap_ms, last_allowed: None, last_asked: 0 }
+ Backoff { first_gap_ms, max_gap_ms, last_allowed: None, last_asked: 0, asked_since_allow: false }
}
pub fn allow(&mut self, now_ms: u64) -> bool {
- let quiet = now_ms.saturating_sub(self.last_asked) >= self.max_gap_ms;
+ let held = !self.asked_since_allow && self.last_allowed.is_some_and(|(at, _)| now_ms.saturating_sub(at) >= HELD_MS);
+ self.asked_since_allow = true;
+ let quiet = held || now_ms.saturating_sub(self.last_asked) >= self.max_gap_ms;
self.last_asked = now_ms;
let gap = match self.last_allowed {
Some((at, gap)) if !quiet => {
@@ -346,6 +358,7 @@ impl Backoff {
_ => self.first_gap_ms,
};
self.last_allowed = Some((now_ms, gap));
+ self.asked_since_allow = false;
true
}
@@ -497,6 +510,29 @@ mod tests {
assert!(b.allow(702_000));
}
+ #[test]
+ fn a_work_area_that_held_a_while_is_set_again_at_once_a_fight_still_backs_off() {
+ let mut b = Backoff::new(2_000, 60_000);
+ // a fight: taken back a second after every set, asked again every second until it is answered
+ assert!(b.allow(0));
+ let mut fight = Vec::new();
+ let mut t = 1_000;
+ while fight.len() < 3 {
+ if b.allow(t) {
+ fight.push(t);
+ }
+ t += 1_000;
+ }
+ assert_eq!(fight, [2_000, 6_000, 14_000], "the pauses grow");
+ // then the last set holds, and the dock reloads (or an island is clicked) every half minute: each is answered at once
+ let last = 14_000;
+ for k in 1..6 {
+ let t = last + k * 30_000;
+ assert!(b.allow(t), "taken back 30 s after it was set: answered at once");
+ assert!(!b.allow(t + 500), "taken back half a second later: that is a fight again");
+ }
+ }
+
#[test]
fn a_reset_backoff_answers_at_once() {
let mut b = Backoff::new(2_000, 60_000);