From 5f98773fc71aa95e7f0593b112a0d4d42f5bca94 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sun, 9 Mar 2025 07:42:21 +0200 Subject: [PATCH 1/3] Update main.lua --- plugins/statistics.koplugin/main.lua | 50 +++++++++++++++++++--------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 259235433..1fbaa1313 100644 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -94,13 +94,23 @@ ReaderStatistics.default_settings = { } function ReaderStatistics:onDispatcherRegisterActions() - Dispatcher:registerAction("toggle_statistics", {category="none", event="ToggleStatistics", title=_("Reading statistics: toggle"), general=true}) - Dispatcher:registerAction("reading_progress", {category="none", event="ShowReaderProgress", title=_("Reading statistics: show progress"), general=true}) - Dispatcher:registerAction("stats_time_range", {category="none", event="ShowTimeRange", title=_("Reading statistics: show time range"), general=true}) - Dispatcher:registerAction("stats_calendar_view", {category="none", event="ShowCalendarView", title=_("Reading statistics: show calendar view"), general=true}) - Dispatcher:registerAction("stats_calendar_day_view", {category="none", event="ShowCalendarDayView", title=_("Reading statistics: show today's timeline"), general=true}) - Dispatcher:registerAction("stats_sync", {category="none", event="SyncBookStats", title=_("Reading statistics: synchronize"), general=true, separator=true}) - Dispatcher:registerAction("book_statistics", {category="none", event="ShowBookStats", title=_("Reading statistics: current book"), reader=true}) + Dispatcher:registerAction("enable_statistics", + {category="string", event="ToggleStatistics", title=_("Reading statistics"), general=true, + args={true, false}, toggle={_("enable"), _("disable")}, arg=false}) + Dispatcher:registerAction("toggle_statistics", + {category="none", event="ToggleStatistics", title=_("Reading statistics: toggle"), general=true}) + Dispatcher:registerAction("reading_progress", + {category="none", event="ShowReaderProgress", title=_("Reading statistics: show progress"), general=true}) + Dispatcher:registerAction("stats_time_range", + {category="none", event="ShowTimeRange", title=_("Reading statistics: show time range"), general=true}) + Dispatcher:registerAction("stats_calendar_view", + {category="none", event="ShowCalendarView", title=_("Reading statistics: show calendar view"), general=true}) + Dispatcher:registerAction("stats_calendar_day_view", + {category="none", event="ShowCalendarDayView", title=_("Reading statistics: show today's timeline"), general=true}) + Dispatcher:registerAction("stats_sync", + {category="none", event="SyncBookStats", title=_("Reading statistics: synchronize"), general=true, separator=true}) + Dispatcher:registerAction("book_statistics", + {category="none", event="ShowBookStats", title=_("Reading statistics: current book"), reader=true}) end function ReaderStatistics:init() @@ -1048,11 +1058,19 @@ function ReaderStatistics:getPageTimeTotalStats(id_book) return total_pages, total_time end -function ReaderStatistics:onToggleStatistics(no_notification) +function ReaderStatistics:onToggleStatistics(arg) + local no_notification, toggle + if type(arg) == "table" then -- Dispatcher-enable/disable + no_notification, toggle = unpack(arg) + if toggle == self.settings.is_enabled then return end + else -- Dispatcher-toggle or Menu-toggle + no_notification = arg + toggle = not self.settings.is_enabled + end if self.settings.is_enabled then -- save data to file self:insertDB() end - self.settings.is_enabled = not self.settings.is_enabled + self.settings.is_enabled = toggle if self.is_doc then if self.settings.is_enabled then self:initData() @@ -1078,7 +1096,7 @@ function ReaderStatistics:addToMainMenu(menu_items) return self.settings.is_enabled end, callback = function() - self:onToggleStatistics(true) + self:onToggleStatistics(true) -- no notification end, }, { @@ -2822,11 +2840,13 @@ function ReaderStatistics:onReadingResumed() end function ReaderStatistics:onReaderReady(config) - self.data = config:readSetting("stats", { performance_in_pages = {} }) - self.doc_md5 = config:readSetting("partial_md5_checksum") - -- we have correct page count now, do the actual initialization work - self:initData() - self.view.footer:maybeUpdateFooter() + if self.settings.is_enabled then + self.data = config:readSetting("stats", { performance_in_pages = {} }) + self.doc_md5 = config:readSetting("partial_md5_checksum") + -- we have correct page count now, do the actual initialization work + self:initData() + self.view.footer:maybeUpdateFooter() + end end function ReaderStatistics:onShowCalendarView() From eafaaa9e686d4205510dae4d6799607b78079811 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sun, 9 Mar 2025 09:14:53 +0200 Subject: [PATCH 2/3] Update main.lua --- plugins/statistics.koplugin/main.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 1fbaa1313..df8d3f86b 100644 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -2840,13 +2840,15 @@ function ReaderStatistics:onReadingResumed() end function ReaderStatistics:onReaderReady(config) - if self.settings.is_enabled then - self.data = config:readSetting("stats", { performance_in_pages = {} }) - self.doc_md5 = config:readSetting("partial_md5_checksum") - -- we have correct page count now, do the actual initialization work - self:initData() - self.view.footer:maybeUpdateFooter() - end + UIManager:nextTick(function() + if self.settings.is_enabled then + self.data = config:readSetting("stats", { performance_in_pages = {} }) + self.doc_md5 = config:readSetting("partial_md5_checksum") + -- we have correct page count now, do the actual initialization work + self:initData() + self.view.footer:maybeUpdateFooter() + end + end) end function ReaderStatistics:onShowCalendarView() From 7cd13433073718017a2400953c3ff6a56ecd5914 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sun, 9 Mar 2025 09:45:16 +0200 Subject: [PATCH 3/3] Update main.lua --- plugins/profiles.koplugin/main.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/profiles.koplugin/main.lua b/plugins/profiles.koplugin/main.lua index a927786da..31b6b9ee4 100644 --- a/plugins/profiles.koplugin/main.lua +++ b/plugins/profiles.koplugin/main.lua @@ -930,11 +930,11 @@ end function Profiles:executeAutoExecEvent(event) if self.autoexec[event] == nil then return end for profile_name in pairs(self.autoexec[event]) do - self:executeAutoExec(profile_name) + self:executeAutoExec(profile_name, event) end end -function Profiles:executeAutoExec(profile_name) +function Profiles:executeAutoExec(profile_name, event) local profile = self.data[profile_name] if profile == nil then return end if profile.settings.auto_exec_ask then @@ -950,9 +950,15 @@ function Profiles:executeAutoExec(profile_name) }) else logger.dbg("Profiles - auto executing:", profile_name) - UIManager:tickAfterNext(function() - Dispatcher:execute(self.data[profile_name]) - end) + if event == "CloseDocument" or event == "CloseDocumentAll" then + UIManager:tickAfterNext(function() + Dispatcher:execute(self.data[profile_name]) + end) + else + UIManager:nextTick(function() + Dispatcher:execute(self.data[profile_name]) + end) + end end end @@ -1004,7 +1010,7 @@ function Profiles:executeAutoExecDocConditional(event) end end if do_execute then - self:executeAutoExec(profile_name) + self:executeAutoExec(profile_name, event) end end end