From bc92ad923ea2c9c3d4352718328556601cb63e27 Mon Sep 17 00:00:00 2001 From: Melik <10296053+melyux@users.noreply.github.com> Date: Thu, 9 Feb 2023 22:45:01 -0800 Subject: [PATCH] Move cache update logic into CoverMenu:updateCache --- plugins/coverbrowser.koplugin/covermenu.lua | 46 +++++++++------------ plugins/coverbrowser.koplugin/main.lua | 3 ++ 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/plugins/coverbrowser.koplugin/covermenu.lua b/plugins/coverbrowser.koplugin/covermenu.lua index 0c4ea7892..d80ca3938 100644 --- a/plugins/coverbrowser.koplugin/covermenu.lua +++ b/plugins/coverbrowser.koplugin/covermenu.lua @@ -43,6 +43,16 @@ local nb_drawings_since_last_collectgarbage = 0 -- in the real Menu class or instance local CoverMenu = {} +function CoverMenu:updateCache(file, status) + if self.cover_info_cache and self.cover_info_cache[file] then + if status then + self.cover_info_cache[file][3] = status + else + self.cover_info_cache[file] = nil + end + end +end + function CoverMenu:updateItems(select_number) -- As done in Menu:updateItems() local old_dimen = self.dimen and self.dimen:copy() @@ -310,9 +320,7 @@ function CoverMenu:updateItems(select_number) enabled = bookinfo and true or false, callback = function() -- Wipe the cache - if self.cover_info_cache and self.cover_info_cache[file] then - self.cover_info_cache[file] = nil - end + self:updateCache(file) BookInfoManager:deleteBookInfo(file) UIManager:close(self.file_dialog) self:updateItems() @@ -334,9 +342,7 @@ function CoverMenu:updateItems(select_number) local orig_purge_callback = button.callback button.callback = function() -- Wipe the cache - if self.cover_info_cache and self.cover_info_cache[file] then - self.cover_info_cache[file] = nil - end + self:updateCache(file) -- And then purge the sidecar folder as expected orig_purge_callback() end @@ -347,9 +353,7 @@ function CoverMenu:updateItems(select_number) local orig_status_callback = button.callback button.callback = function() -- Update the cache - if self.cover_info_cache and self.cover_info_cache[file] then - self.cover_info_cache[file][3] = status - end + self:updateCache(file, status) -- And then set the status on file as expected orig_status_callback() end @@ -469,9 +473,7 @@ function CoverMenu:onHistoryMenuHold(item) enabled = bookinfo and true or false, callback = function() -- Wipe the cache - if self.cover_info_cache and self.cover_info_cache[file] then - self.cover_info_cache[file] = nil - end + self:updateCache(file) BookInfoManager:deleteBookInfo(file) UIManager:close(self.histfile_dialog) self:updateItems() @@ -493,9 +495,7 @@ function CoverMenu:onHistoryMenuHold(item) local orig_purge_callback = button.callback button.callback = function() -- Wipe the cache - if self.cover_info_cache and self.cover_info_cache[file] then - self.cover_info_cache[file] = nil - end + self:updateCache(file) -- And then purge the sidecar folder as expected orig_purge_callback() end @@ -507,9 +507,7 @@ function CoverMenu:onHistoryMenuHold(item) local orig_status_callback = button.callback button.callback = function() -- Update the cache - if self.cover_info_cache and self.cover_info_cache[file] then - self.cover_info_cache[file][3] = status - end + self:updateCache(file, status) -- And then set the status on file as expected orig_status_callback() end @@ -622,9 +620,7 @@ function CoverMenu:onCollectionsMenuHold(item) enabled = bookinfo and true or false, callback = function() -- Wipe the cache - if self.cover_info_cache and self.cover_info_cache[file] then - self.cover_info_cache[file] = nil - end + self:updateCache(file) BookInfoManager:deleteBookInfo(file) UIManager:close(self.collfile_dialog) self:updateItems() @@ -646,9 +642,7 @@ function CoverMenu:onCollectionsMenuHold(item) local orig_purge_callback = button.callback button.callback = function() -- Wipe the cache - if self.cover_info_cache and self.cover_info_cache[file] then - self.cover_info_cache[file] = nil - end + self:updateCache(file) -- And then purge the sidecar folder as expected orig_purge_callback() end @@ -659,9 +653,7 @@ function CoverMenu:onCollectionsMenuHold(item) local orig_status_callback = button.callback button.callback = function() -- Update the cache - if self.cover_info_cache and self.cover_info_cache[file] then - self.cover_info_cache[file][3] = status - end + self:updateCache(file, status) -- And then set the status on file as expected orig_status_callback() end diff --git a/plugins/coverbrowser.koplugin/main.lua b/plugins/coverbrowser.koplugin/main.lua index f030a2fbc..78f2b25ee 100644 --- a/plugins/coverbrowser.koplugin/main.lua +++ b/plugins/coverbrowser.koplugin/main.lua @@ -527,6 +527,7 @@ function CoverBrowser:setupFileManagerDisplayMode(display_mode) -- In both mosaic and list modes, replace original methods with those from -- our generic CoverMenu local CoverMenu = require("covermenu") + FileChooser.updateCache = CoverMenu.updateCache FileChooser.updateItems = CoverMenu.updateItems FileChooser.onCloseWidget = CoverMenu.onCloseWidget @@ -592,6 +593,7 @@ local function _FileManagerHistory_updateItemTable(self) -- In both mosaic and list modes, replace original methods with those from -- our generic CoverMenu local CoverMenu = require("covermenu") + hist_menu.updateCache = CoverMenu.updateCache hist_menu.updateItems = CoverMenu.updateItems hist_menu.onCloseWidget = CoverMenu.onCloseWidget -- Also replace original onMenuHold (it will use original method, so remember it) @@ -670,6 +672,7 @@ local function _FileManagerCollections_updateItemTable(self) -- In both mosaic and list modes, replace original methods with those from -- our generic CoverMenu local CoverMenu = require("covermenu") + coll_menu.updateCache = CoverMenu.updateCache coll_menu.updateItems = CoverMenu.updateItems coll_menu.onCloseWidget = CoverMenu.onCloseWidget -- Also replace original onMenuHold (it will use original method, so remember it)