pop-os/cosmic-files

No images renderd for icons

Opened this issue · 3 comments

First of all, I'll clarify that I'm not using cosmic desktop; I'm trying to use cosmic-files under swaywm.

I'm trying out cosmic-files, and files don't render icons. The console output reads lots of lines like:

[2024-02-19T18:47:26Z WARN  cosmic_files::mime_icon] failed to get icon for MimeIconKey { path: "/home/hugo/downloads/Untitled.svg", size: 32 }: (icon not found, (Error type: IoError)

A quick glace at the code indicates that this is in src/mime_icon.rs, MimeIconCache::get calls systemicons::get_icon. I looked at its code and it seems to use Gtk under the hood. I'm using nemo (gtk3) as a file manager and icons for it render fine, so I'm fairly certain that a theme is properly installed and configured.

Huh, running the example from https://github.com/uriegel/systemicons/ fails, so maybe the bug is not specific to this crate?

Any special dependency that I should keep in mind in this context?

Huh, running the example from https://github.com/uriegel/systemicons/ fails, so maybe the bug is not specific to this crate?

The example's failure seem unrelated, since it's actually SEGFAULT'ing.

I'm able to replicate this on my Sway machine too. COSMIC Files is no longer using the crate above but instead using features exposed by libcosmic directly. libcosmic is using freedesktop-icons instead of the (likely unmaintained?) crate above.

In any case, I tested all of this with a quick program that you can try too:

use std::{fs, path::Path};

use cosmic::widget::icon;
use xdg_mime::SharedMimeInfo;

fn main() {
    let path_arg = std::env::args().nth(1).unwrap();
    let path = Path::new(&path_arg);
    let mime_info = SharedMimeInfo::new();

    let mimes = if path.is_file() {
        mime_info.get_mime_types_from_file_name(&path_arg)
    } else {
        let mut mimes = vec![];
        for entry in fs::read_dir(path).unwrap() {
            let entry = entry.unwrap().path();
            let path = entry.to_str().unwrap();
            mimes.extend(mime_info.get_mime_types_from_file_name(path));
        }
        mimes
    };

    let theme = std::env::args().nth(2).unwrap_or_else(|| "Adwaita".into());
    for mime in mimes {
        println!("{mime}");
        for name in mime_info.lookup_icon_names(&mime) {
            let path = icon::from_name(name.clone()).path();
            println!("\t[libcosmic] {name} => {path:?}");

            let path = freedesktop_icons::lookup(&name).with_theme(&theme).find();
            println!("\t[freedesktop-icons] {name} => {path:?}")
        }
    }

    for theme in freedesktop_icons::list_themes() {
        println!("Theme: {theme}");
    }
}

And Cargo.toml:

[package]
name = "mimetest"
version = "0.1.0"
edition = "2021"

[dependencies]
freedesktop-icons = "0.2"
xdg-mime = "0.3"

[dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic.git"
features = ["desktop"]

I tried it on a few folders on my main computer. Every path was None. It's possible that we botched something in our Sway configs or how we launch it (e.g. missing XDG variables), but Thunar correctly renders icons and COSMIC Files works on a COSMIC session. I'll look into it.

EDIT: I updated the example code above. I made progress with it too.