diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2023-03-18 16:14:38 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-19 01:26:37 +0000 |
commit | b79cd5cf6ea4addd9d7c47cea9d385883305b734 (patch) | |
tree | 30d607406a367362800546b54809b0415f107b4c /Userland/Libraries/LibGUI | |
parent | ebb9c3a4304e9860386189bc6ac43a11f84f6ec1 (diff) | |
download | serenity-b79cd5cf6ea4addd9d7c47cea9d385883305b734.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r-- | Userland/Libraries/LibGUI/FileSystemModel.cpp | 23 |
1 files 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<void> { - 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<void> { + 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) { |