From 6d3634b58d1926ffd67f96841fdeffeaf1a663c7 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 6 Feb 2016 23:33:52 +0800 Subject: [PATCH 1/3] fix occationally stats being wiped out --- plugins/statistics.koplugin/main.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 733668a6b..973623228 100755 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -405,10 +405,14 @@ function ReaderStatistics:onPageUpdate(pageno) self.current_period = self.current_period + diff_time self.data.total_time_in_sec = self.data.total_time_in_sec + diff_time self.data.performance_in_pages[curr_time.sec] = pageno + -- we cannot save stats each time this is a page update event, + -- because the self.data may not even be initialized when such a event + -- comes, which will render a blank stats written into doc settings + -- and all previous stats are totally wiped out. + self.ui.doc_settings:saveSetting("stats", self.data) end self.last_time = curr_time - self.ui.doc_settings:saveSetting("stats", self.data) end end From 2ea217296b9f1a82c0248193c569ecda6a0de0d6 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 6 Feb 2016 23:39:11 +0800 Subject: [PATCH 2/3] comments on the delayed stats initialization --- plugins/statistics.koplugin/main.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 973623228..87b723f34 100755 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -490,6 +490,7 @@ function ReaderStatistics:saveSettings(fields) end function ReaderStatistics:onReadSettings(config) + -- delay initialization for accurate total pages count of the doc UIManager:scheduleIn(0.1, function() self:initData(config) end) end From 493c88782947a2856c20a40af1ad0d757705ea73 Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 7 Feb 2016 21:48:13 +0800 Subject: [PATCH 3/3] fix travis testfront --- spec/unit/readerfooter_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/unit/readerfooter_spec.lua b/spec/unit/readerfooter_spec.lua index 24e0ecaf0..865f030f3 100644 --- a/spec/unit/readerfooter_spec.lua +++ b/spec/unit/readerfooter_spec.lua @@ -13,7 +13,8 @@ describe("Readerfooter module", function() readerui.view.footer.settings.all_at_once = true readerui.view.footer:updateFooterPage() timeinfo = readerui.view.footer:getTimeInfo() - assert.are.same('B:0% | '..timeinfo..' | 1 / 1 | => 0 | R:100% | TB: 00:00 | TC: 00:00', + -- stats has not been initialized here, so we get na TB and TC + assert.are.same('B:0% | '..timeinfo..' | 1 / 1 | => 0 | R:100% | TB: na | TC: na', readerui.view.footer.progress_text.text) end)