diff --git a/frontend/ui/elements/screen_notification_menu_table.lua b/frontend/ui/elements/screen_notification_menu_table.lua index 2d051eda6..d2ab2b6d1 100644 --- a/frontend/ui/elements/screen_notification_menu_table.lua +++ b/frontend/ui/elements/screen_notification_menu_table.lua @@ -1,4 +1,6 @@ local Notification = require("ui/widget/notification") +local TextViewer = require("ui/widget/textviewer") +local UIManager = require("ui/uimanager") local _ = require("gettext") local band = bit.band @@ -76,5 +78,26 @@ This allows selecting which to show or hide.]]), end, separator = true, }, + { + text = _("Show past notifications"), + callback = function() + local content = require("ui/widget/notification"):getPastMessages() + + if not content or #content == 0 then + content = _("No notifications available.") + else + content = table.concat(content, "\n") + end + + local textviewer + textviewer = TextViewer:new{ + title = _("Past notifications"), + text = content, + justified = false, + } + UIManager:show(textviewer) + end, + keep_menu_open = true, + }, } } diff --git a/frontend/ui/widget/notification.lua b/frontend/ui/widget/notification.lua index c927e3f75..fdd42c0ad 100644 --- a/frontend/ui/widget/notification.lua +++ b/frontend/ui/widget/notification.lua @@ -48,6 +48,9 @@ local SOURCE_ALL = SOURCE_BOTTOM_MENU + SOURCE_DISPATCHER + SOURCE_OTHER +-- Maximum number of saved message text +local MAX_NB_PAST_MESSAGES = 20 + local Notification = InputContainer:extend{ face = Font:getFace("x_smallinfofont"), text = _("N/A"), @@ -73,6 +76,7 @@ local Notification = InputContainer:extend{ SOURCE_SOME = SOURCE_SOME, SOURCE_DEFAULT = SOURCE_DEFAULT, SOURCE_ALL = SOURCE_ALL, + _past_messages = {}, -- a static class member to store the N last messages text } function Notification:init() @@ -164,6 +168,10 @@ function Notification:notify(arg, source, refresh_after) return false end +function Notification:getPastMessages() + return self._past_messages +end + function Notification:_cleanShownStack() -- Clean stack of shown notifications if self._shown_idx then @@ -204,10 +212,15 @@ function Notification:onShow() if self.timeout then UIManager:scheduleIn(self.timeout, function() UIManager:close(self) end) end + + if #self._past_messages >= MAX_NB_PAST_MESSAGES then + table.remove(self._past_messages) + end + table.insert(self._past_messages, 1, os.date("%X: ") .. self.text) + return true end - function Notification:onTapClose() if self.toast then return end -- should not happen UIManager:close(self) diff --git a/frontend/version.lua b/frontend/version.lua index 67917ef09..30fe881c3 100644 --- a/frontend/version.lua +++ b/frontend/version.lua @@ -2,6 +2,8 @@ This module helps with retrieving version information. ]] +local VERSION_LOG_FILE = "version.log" + local Version = {} --- Returns current KOReader git-rev. @@ -86,4 +88,47 @@ function Version:getBuildDate() return self.date end +--- Get last line in `VERSION_LOG_FILE`. +-- @treturn last line in `VERSION_LOG_FILE` or an empty string +function Version:getLastLogLine() + local log_file = io.open(VERSION_LOG_FILE, "r") + local last_log_line + if log_file then + for line in log_file:lines() do + last_log_line = line + end + log_file:close() + end + + return last_log_line or "" +end + +--- Append text to a `VERSION_LOG_FILE`. +-- @string text text to be appended +function Version:appendToLogFile(text) + local log_file = io.open(VERSION_LOG_FILE, "a") + if not log_file then + return + end + log_file:write(text, "\n") + log_file:close() + return true +end + +--- Updates `VERSION_LOG_FILE` and keep the file small +-- @string model device model (may contain spaces) +function Version:updateVersionLog(current_model) + local last_line = Version:getLastLogLine() + + local dummy, dummy, last_version, last_model = last_line:match("(.-), (.-), (.-), (.-)$") + self.last_version = last_version or "last version not found" + self.last_model = last_model or "last model not found" + + if self.rev ~= last_version or current_model ~= last_model then + -- Appends KOReader git-rev, model and current date to the `VERSION_LOG_FILE` + -- in the format 'YYYY-mm-dd, HH:MM:SS, git-rev, model' + self:appendToLogFile(os.date("%Y-%m-%d, %X, ") .. self.rev .. ", " .. current_model) + end +end + return Version diff --git a/reader.lua b/reader.lua index a5aa48c68..cd2c0750e 100755 --- a/reader.lua +++ b/reader.lua @@ -26,7 +26,8 @@ local userpatch = require("userpatch") userpatch.applyPatches(userpatch.early_once) userpatch.applyPatches(userpatch.early) -io.write(" [*] Version: ", require("version"):getCurrentRevision(), "\n\n") +local Version = require("version") +io.write(" [*] Version: ", Version:getCurrentRevision(), "\n\n") -- Load default settings G_defaults = require("luadefaults"):open() @@ -185,6 +186,9 @@ end local CanvasContext = require("document/canvascontext") CanvasContext:init(Device) +-- Update the version log file if there was an update or the device has changed +Version:updateVersionLog(Device.model) + -- Handle one time migration stuff (settings, deprecation, ...) in case of an upgrade... require("ui/data/onetime_migration")