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: a pin's own picture stays while its app runs (785)

gelenmedyab4572830a7ac
diff --git a/crates/rf-win/src/dock/iconload.rs b/crates/rf-win/src/dock/iconload.rs
index 8d1450d0..0dff1f60 100644
--- a/crates/rf-win/src/dock/iconload.rs
+++ b/crates/rf-win/src/dock/iconload.rs
@@ -270,9 +270,19 @@ pub fn program_frames(p: &Path, index: i32) -> Option<Vec<FrameInfo>> {
/// Whether a program's file carries an icon of its own. A small launcher may have none: the shell then quietly answers with its
/// generic document picture instead of failing, so the caller has to choose a better source itself.
pub fn has_own_icon(p: &Path) -> bool {
+ // a picture file is an icon of its own (issue 785: a pin's custom .ico has no icon RESOURCES, was taken for a file without an
+ // icon, and gave way to the running window's while the app ran)
+ if is_picture_file(p) {
+ return p.is_file();
+ }
program_frames(p, 0).is_some_and(|f| !f.is_empty())
}
+/// Whether `p` names a picture (an `.ico`, `.png`, ...) rather than a program or a shortcut: an icon somebody chose for a pin.
+pub fn is_picture_file(p: &Path) -> bool {
+ p.extension().is_some_and(|e| ["ico", "png", "bmp", "jpg", "jpeg", "gif", "webp"].iter().any(|x| e.eq_ignore_ascii_case(x)))
+}
+
/// What the remembered answer belongs to: the file and the time it was last changed, so an updated launcher is probed again.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct OwnIconKey {
diff --git a/crates/rf-win/src/dock/model.rs b/crates/rf-win/src/dock/model.rs
index 40dc6a2c..3aadbf44 100644
--- a/crates/rf-win/src/dock/model.rs
+++ b/crates/rf-win/src/dock/model.rs
@@ -123,7 +123,9 @@ impl DockApp {
for &w in self.windows.iter().take(3) {
add(IconSource::Window(w));
}
- if looks_packaged(&self.key) {
+ // (not when the app was given a picture of its own: the package logo is ranked first and would replace it, issue 785)
+ let chosen_picture = matches!(&self.icon, IconSource::File(p) if super::iconload::is_picture_file(p));
+ if looks_packaged(&self.key) && !chosen_picture {
add(IconSource::Packaged(self.key.clone()));
}
chain
@@ -795,6 +797,24 @@ mod tests {
let mut packaged_pin_running = app(merge(&[pin("P", Some(r"C:\i\i.exe"), Some("Pkg.Name_abcdefghijklm!App"))], vec![group(vec![t(5)])], 0));
packaged_pin_running.windows = vec![5];
assert_eq!(packaged_pin_running.icon_chain().last(), Some(&IconSource::Packaged("pkg.name_abcdefghijklm!app".into())));
+ // ... but a picture the user gave the pin is never replaced by the package logo (issue 785)
+ packaged_pin_running.icon = IconSource::File(PathBuf::from(r"C:\icons\mine.ico"));
+ assert!(!packaged_pin_running.icon_chain().iter().any(|s| matches!(s, IconSource::Packaged(_))));
+ }
+
+ #[test]
+ fn a_pin_with_a_picture_of_its_own_keeps_it_while_the_app_runs() {
+ // issue 785: the .ico has no icon resources; the merge must not take it for a file without an icon
+ let mut p = pin("Firefox", Some(r"C:\f\firefox.exe"), None);
+ p.icon = IconSource::File(PathBuf::from(r"C:\icons\fox.ico"));
+ let picture_is_an_icon = |f: &Path| super::super::iconload::is_picture_file(f);
+ let items = merge_with(&[p], vec![group(vec![task(7, r"C:\f\firefox.exe", None)])], 0, picture_is_an_icon);
+ match items.into_iter().next() {
+ Some(DockItem::App(a)) => assert_eq!(a.icon, IconSource::File(PathBuf::from(r"C:\icons\fox.ico"))),
+ _ => panic!("an app"),
+ }
+ assert!(super::super::iconload::is_picture_file(Path::new(r"C:\a\B.ICO")));
+ assert!(!super::super::iconload::is_picture_file(Path::new(r"C:\a\b.exe")));
}
#[test]