mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Version log and (limited) notifications log (#10178)
This PR will close #1257 and #3418.
This commit is contained in:
@@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user