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.

Dock: the bin's picture comes from the icon of its state, not the shell's cache (887)

denfryc9081917eba4
diff --git a/crates/rf-app/src/dock/bin_feed.rs b/crates/rf-app/src/dock/bin_feed.rs
index 177ff458..1ae08d79 100644
--- a/crates/rf-app/src/dock/bin_feed.rs
+++ b/crates/rf-app/src/dock/bin_feed.rs
@@ -73,6 +73,7 @@ pub(super) fn start(cx: &mut App) {
if let Some(full) = full {
cx.update(|cx| {
if cx.try_global::<BinState>().is_some_and(|s| s.full != Some(full)) {
+ log::info!("dock: the recycle bin is {} now", if full { "full" } else { "empty" });
// a picture another dock made a moment ago is of the old state
super::icons::forget_shared(&icon_key());
cx.update_global::<BinState, _>(|s, _| s.full = Some(full));
diff --git a/crates/rf-app/src/dock/middle.rs b/crates/rf-app/src/dock/middle.rs
index 06b33df3..e1b5501b 100644
--- a/crates/rf-app/src/dock/middle.rs
+++ b/crates/rf-app/src/dock/middle.rs
@@ -109,6 +109,8 @@ pub struct MiddleIsland {
slots: Vec<Slot>,
/// Per item: the key its icon is cached under and where the icon can come from, best first (worked out once per refresh, not per frame).
icon_srcs: Vec<Option<(String, Vec<IconSource>)>>,
+ /// The Recycle Bin turned while its icon was loading: that load may bring the old state's picture, so it is asked again after.
+ bin_again: bool,
icons: IconCache,
/// The same icons at every size they are drawn at (the rest size, the peak and the steps between, see `icon_levels`): what is
/// drawn comes from here, `icons` keeps the largest picture of each for the menus and the state of the loads.
@@ -237,6 +239,7 @@ impl MiddleIsland {
items: Vec::new(),
slots: Vec::new(),
icon_srcs: Vec::new(),
+ bin_again: false,
icons: IconCache::default(),
levels: LevelStore::default(),
// (the dock is not in the host's list yet while its islands are made: a secondary dock's unit is asked for at its first load)
@@ -294,6 +297,8 @@ impl MiddleIsland {
cx.observe_global::<super::bin_feed::BinState>(|me: &mut Self, cx| {
if me.icons.mark_stale_key(&super::bin_feed::icon_key()) {
me.load_icons(cx);
+ } else {
+ me.bin_again = true;
}
})
.detach();
@@ -472,6 +477,15 @@ impl MiddleIsland {
// (docks of several monitors ask for the same icons: with the same sizes they share one load, see `icons::load_levels_shared`)
let shared = host::dock_count(cx) > 1;
let mut wanted: Vec<(String, Vec<IconSource>)> = self.icon_srcs.iter().flatten().cloned().collect();
+ // (the Recycle Bin, its state known: the picture of that state first, the shell's after it, see `recycle_bin_icon`)
+ if let Some(full) = cx.try_global::<super::bin_feed::BinState>().and_then(|s| s.full) {
+ let bin = super::bin_feed::icon_key();
+ for (_, srcs) in wanted.iter_mut().filter(|(k, _)| *k == bin) {
+ if let Some(own) = rf_win::dock::model::recycle_bin_icon(full) {
+ srcs.insert(0, own);
+ }
+ }
+ }
// (and the pictures of the pinned apps the left island shows)
wanted.extend(self.left_pins.iter().map(|(_, key, srcs)| (key.clone(), srcs.clone())));
for (key, src) in wanted {
@@ -497,6 +511,12 @@ impl MiddleIsland {
icon_levels::retire(vec![old], cx);
}
let retry = me.icons.finish(&key, top, Instant::now());
+ if me.bin_again && key == super::bin_feed::icon_key() {
+ me.bin_again = false;
+ if me.icons.mark_stale_key(&key) {
+ me.load_icons(cx);
+ }
+ }
cx.notify();
// a picture for the left island's launchers: it draws again
if me.left_pins.iter().any(|(_, k, _)| *k == key)
diff --git a/crates/rf-win/src/dock/model.rs b/crates/rf-win/src/dock/model.rs
index 3aadbf44..e8507545 100644
--- a/crates/rf-win/src/dock/model.rs
+++ b/crates/rf-win/src/dock/model.rs
@@ -62,6 +62,23 @@ pub enum Place {
Downloads,
}
+/// The Recycle Bin's picture for a state the caller knows (issue 887): the icon Windows keeps for "full" or "empty" under the bin's
+/// class (`DefaultIcon`, the user's own choice first), as a resource of its file. The shell's `shell:RecycleBinFolder` picture comes
+/// from its icon cache, which can still hold the old state for a while after the bin changed (the dock asked a second after a file
+/// was restored from the bin and got the full bin, and kept it). `None` when the registry names no picture: the shell's then.
+pub fn recycle_bin_icon(full: bool) -> Option<IconSource> {
+ use windows::Win32::System::Registry::{HKEY_CLASSES_ROOT, HKEY_CURRENT_USER};
+ const CLSID: &str = "{645FF040-5081-101B-9F08-00AA002F954E}";
+ let value = if full { "full" } else { "empty" };
+ let user = format!(r"Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{CLSID}\DefaultIcon");
+ let machine = format!(r"CLSID\{CLSID}\DefaultIcon");
+ let text = crate::bench::reg_string(HKEY_CURRENT_USER, &user, value).or_else(|| crate::bench::reg_string(HKEY_CLASSES_ROOT, &machine, value))?;
+ // (`reg_string` can hand back what follows the value's end too: an expanded value is shorter than the size Windows reports)
+ let text = text.split(char::from(0)).next().unwrap_or_default();
+ let (file, index) = crate::tasklist::icon_resource(&crate::localized::expand_env(text))?;
+ Some(IconSource::Resource { file, index })
+}
+
impl Place {
/// The shell parsing name the icon is asked with.
pub fn icon_source(self) -> IconSource {
@@ -487,6 +504,21 @@ mod shape_tests {
mod tests {
use super::*;
+ /// Issue 887: Windows keeps a picture for each state of the bin, and they are not the same one.
+ #[test]
+ fn the_recycle_bin_has_its_own_picture_for_full_and_for_empty() {
+ let (full, empty) = (recycle_bin_icon(true), recycle_bin_icon(false));
+ let (Some(IconSource::Resource { file: ff, index: fi }), Some(IconSource::Resource { file: ef, index: ei })) = (full, empty) else {
+ panic!("no DefaultIcon for the bin's states");
+ };
+ assert!(ff.exists() && ef.exists(), "{ff:?} {ef:?}");
+ assert!(!ff.to_string_lossy().contains('%'), "environment variables expanded");
+ assert_ne!((&ff, fi), (&ef, ei));
+ // and the picture itself comes from the file, not from the shell's icon cache
+ let got = crate::dock::iconload::load_levels(&[IconSource::Resource { file: ff, index: fi }], &[64]).expect("the full bin's picture");
+ assert_eq!(got.levels[0].width, 64);
+ }
+
fn task(hwnd: isize, exe: &str, id: Option<&str>) -> Task {
Task { hwnd, title: format!("w{hwnd}"), pid: hwnd as u32, exe: Some(PathBuf::from(exe)), app_id: id.map(String::from), minimized: false, relaunch: None }
}