From b79cd5cf6ea4addd9d7c47cea9d385883305b734 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sat, 18 Mar 2023 16:14:38 -0400 Subject: [PATCH] LibGUI: Update progress of thumbnail generations on failure Not doing it result in FileManager's progress bar being left as incomplete even if all jobs were finish. --- Userland/Libraries/LibGUI/FileSystemModel.cpp | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 99a8a8a50a..8ca43ac867 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -699,12 +699,8 @@ bool FileSystemModel::fetch_thumbnail_for(Node const& node) auto const action = [path](auto&) { return render_thumbnail(path); }; - auto const on_complete = [path, weak_this](auto thumbnail) -> ErrorOr { - s_thumbnail_cache.with_locked([path, thumbnail](auto& cache) { - cache.thumbnail_cache.set(path, thumbnail); - cache.loading_thumbnails.remove(path); - }); + auto const update_progress = [weak_this](bool with_success) { if (auto strong_this = weak_this.strong_ref(); !strong_this.is_null()) { strong_this->m_thumbnail_progress++; if (strong_this->on_thumbnail_progress) @@ -714,12 +710,23 @@ bool FileSystemModel::fetch_thumbnail_for(Node const& node) strong_this->m_thumbnail_progress_total = 0; } - strong_this->did_update(UpdateFlag::DontInvalidateIndices); + if (with_success) + strong_this->did_update(UpdateFlag::DontInvalidateIndices); } + }; + + auto const on_complete = [path, update_progress](auto thumbnail) -> ErrorOr { + s_thumbnail_cache.with_locked([path, thumbnail](auto& cache) { + cache.thumbnail_cache.set(path, thumbnail); + cache.loading_thumbnails.remove(path); + }); + + update_progress(true); + return {}; }; - auto const on_error = [path](Error error) -> void { + auto const on_error = [path, update_progress](Error error) -> void { // Note: We need to defer that to avoid the function removing its last reference // i.e. trying to destroy itself, which is prohibited. Core::EventLoop::current().deferred_invoke([&] { @@ -731,6 +738,8 @@ bool FileSystemModel::fetch_thumbnail_for(Node const& node) cache.loading_thumbnails.remove(path); }); }); + + update_progress(false); }; s_thumbnail_cache.with_locked([path, action, on_complete, on_error](auto& cache) {