diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 3fff552d49..78dbdc929b 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -707,8 +707,8 @@ bool FileSystemModel::fetch_thumbnail_for(Node const& node) auto const action = [path](auto&) { return render_thumbnail(path); }; - auto const update_progress = [weak_this](bool with_success) { + using namespace AK::TimeLiterals; if (auto strong_this = weak_this.strong_ref(); !strong_this.is_null()) { strong_this->m_thumbnail_progress++; if (strong_this->on_thumbnail_progress) @@ -718,17 +718,24 @@ bool FileSystemModel::fetch_thumbnail_for(Node const& node) strong_this->m_thumbnail_progress_total = 0; } - if (with_success) + if (with_success && (!strong_this->m_ui_update_timer.is_valid() || strong_this->m_ui_update_timer.elapsed_time() > 100_ms)) { strong_this->did_update(UpdateFlag::DontInvalidateIndices); + strong_this->m_ui_update_timer.start(); + } } }; - auto const on_complete = [path, update_progress](auto thumbnail) -> ErrorOr { - s_thumbnail_cache.with_locked([path, thumbnail](auto& cache) { + auto const on_complete = [weak_this, path, update_progress](auto thumbnail) -> ErrorOr { + auto finished_generating_thumbnails = false; + s_thumbnail_cache.with_locked([path, thumbnail, &finished_generating_thumbnails](auto& cache) { cache.thumbnail_cache.set(path, thumbnail); cache.loading_thumbnails.remove(path); + finished_generating_thumbnails = cache.loading_thumbnails.is_empty(); }); + if (auto strong_this = weak_this.strong_ref(); finished_generating_thumbnails && !strong_this.is_null()) + strong_this->m_ui_update_timer.reset(); + update_progress(true); return {}; diff --git a/Userland/Libraries/LibGUI/FileSystemModel.h b/Userland/Libraries/LibGUI/FileSystemModel.h index dccccab5c6..7eb1302458 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.h +++ b/Userland/Libraries/LibGUI/FileSystemModel.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -174,6 +175,8 @@ private: unsigned m_thumbnail_progress { 0 }; unsigned m_thumbnail_progress_total { 0 }; + Core::ElapsedTimer m_ui_update_timer; + Optional> m_allowed_file_extensions; bool m_should_show_dotfiles { false };