DDE前端(四):缩略图set_icon (get_thumbnails)

本文介绍了一种改进的缩略图加载方案,通过后端延迟返回缩略图路径及前端使用图标显示策略,解决了缩略图加载不完整的问题,并讨论了文件监听与缩略图生成时机的优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、 缩略图不完整

https://tower.im/projects/1c0cd0c59ef941298c6e6b2ba6833b91/todos/e1b395bcf0514678949ac17c7a89d538/

现在已经可以显示完整的缩略图了

解决方案如下:

1.后端添加时间检测,THUMBNAILS_CREATEION_DELAY = 3s后才返回thumbnails路径

    //2' lookup existing thumbnail
    thumbnail_path = gnome_desktop_thumbnail_factory_lookup (factory, uri, mtime);
    g_debug ("uri: %s\nthumbnail_path: %s\n", uri, thumbnail_path);

    //3' create thumbnail if not exist
    if (thumbnail_path == NULL)
    {
        time_t current_time = 0;
        time (&current_time);
        g_message("%d",current_time);
        g_message("%d",mtime);
        if (current_time - mtime < THUMBNAIL_CREATION_DELAY)
        {
            g_debug ("thumbnail creation delayed: %d", current_time - mtime);
            return NULL;
        }

2. 前端在没有返回thumbnails path 前,用get_icon 显示

  #1. first use the get_icon to show

 

    set_icon : (src = null) =>
        if src == null
            if DCore.DEntry.can_thumbnail(@_entry) 
                if (icon = DCore.DEntry.get_thumbnail(@_entry)) == null
                    #1. first use the get_icon to show
                    if (icon = DCore.DEntry.get_icon(@_entry)) != null 
                        @item_icon.className = ""
                    else
                        icon = DCore.get_theme_icon("unknown", D_ICON_SIZE_NORMAL) 
                        @item_icon.className = ""
                    #2. then set the 1s timeout to check the get_thumbnail 
                    that = @
                    clearTimeout(t) if t
                    t = setTimeout(->
                        echo 'setTimeout in'
                        if (icon = DCore.DEntry.get_thumbnail(that._entry)) != null
                            echo "entry_tmp get_thumbnail true"
                            that.item_icon.className = "previewshadow"  
                            that.item_icon.src = icon
                            # that.set_icon(src)  
                            # that = null
                    ,3000)# gfile_lookup_thumbnail in thumbnails #define THUMBNAIL_CREATION_DELAY  3

                else 
                    @item_icon.className = "previewshadow"

            else if (icon = DCore.DEntry.get_icon(@_entry)) != null 
                @item_icon.className = ""
            else
                icon = DCore.get_theme_icon("unknown", D_ICON_SIZE_NORMAL)
                @item_icon.className = ""
        else
            icon = src
        @item_icon.src = icon
        return

 

3. 3秒后检测是否返回了thumbnails path true

 #2. then set the 1s timeout to check the get_thumbnail
 

 核心在于

clearTimeout(t) if t

现在已经可以保证仅在t2后开始真正的get_thumbnails

如果不在正确的时候 if t 时clearTimeout(t),

那么 setTimeout  的次数 绝对 = update_item + 1(如果setTimeout的时间大于 生成缩略图的时间t3)

 

注:setTimeout的时间t_set必须至少要大于 空白时间t2(t2<2s),所以我设置为了3s ,保险些

也就是说,从开始存储图片,到最终看到图片缩略图时间T为:

T =   t1 + t_set (setTimeout) = 1 + 3 = 4s

显然这不是T的最小值

T最小值是去掉t 中的 t2 (监听文件存储结束),以及将t_set 最小化

但是第一点是做不到的现在,而因为第一点做不到,所以第二点t_set就只能大点(因为get_thumbnails中的是3s),来保证在文件有足够的时间存储结束。

 

4. inotify端如下:

void handle_update(GFile* f)
{
    g_message("handle_update");
    if (g_file_query_file_type(f, G_FILE_QUERY_INFO_NONE ,NULL) != G_FILE_TYPE_UNKNOWN) {
        char* path = g_file_get_path(f);
        Entry* entry = dentry_create_by_path(path);
        g_free(path);

        JSObjectRef json = json_create();
        json_append_nobject(json, "entry", entry, g_object_ref, g_object_unref);
        js_post_message("item_update", json);

        g_object_unref(entry);
    }
}

有"handle_update" 就一定有 " item_update"

 

还有问题如下:

1. get_thumbnails 中设定的3s是随意大致设定的,不能检测何时才完成. 这个时间有没有办法确定。或者监听。

2.而后端inotify监听所有,item只要任何一个item有任何一点变化(仅仅是图片的写入过程也算)就会update_item,导致调用次数很多

    item_update : =>
        echo "item_update"
        @set_icon()

如果保存一个1G的视频到桌面,那桌面肯定卡的不行了!

注:从smb中复制了deepin的ISO镜像,桌面是卡死了,但是复制完了后item_update竟然只有两次(复制期间,webinspector黑了)

求解释。。。 @夏彬

解决方案:

1. 后端inotify中将监听时间间隔必须降低些

现在监听时间太短了,完全没必要,其实1s监听一次就可以了

 

可以有效提高桌面的流畅性,否则一直update_item很卡的。

这也是为何桌面保存图片时超级卡,或者复制文件到桌面时。

2. 现在的核心问题是:不知道文件何时保存完

也没有直接的库函数可以调用。

item_update 应该是在文件保存结束后才进行。

如何监听文件是否保存结束???  @夏彬

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值