mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
System Stat plugin (#2699)
This commit is contained in:
@@ -56,6 +56,7 @@ local order = {
|
||||
"ota_update", -- if Device:isKindle() or Device:isKobo() or Device:isPocketBook() or Device:isAndroid()
|
||||
"version",
|
||||
"help",
|
||||
"system_statistics",
|
||||
"----------------------------",
|
||||
"exit",
|
||||
},
|
||||
|
||||
@@ -70,6 +70,7 @@ local order = {
|
||||
"ota_update", -- if Device:isKindle() or Device:isKobo() or Device:isPocketBook() or Device:isAndroid()
|
||||
"version",
|
||||
"help",
|
||||
"system_statistics",
|
||||
"----------------------------",
|
||||
"exit",
|
||||
},
|
||||
|
||||
@@ -747,7 +747,7 @@ function UIManager:_initAutoSuspend()
|
||||
|
||||
if isAutoSuspendEnabled() then
|
||||
self.auto_suspend_action = function()
|
||||
local now = util.gettime()
|
||||
local now = os.time()
|
||||
-- Do not repeat auto suspend procedure after suspend.
|
||||
if self.last_action_sec + self.auto_suspend_sec <= now then
|
||||
self.event_handlers["Suspend"]()
|
||||
@@ -759,7 +759,7 @@ function UIManager:_initAutoSuspend()
|
||||
end
|
||||
|
||||
function UIManager:_startAutoSuspend()
|
||||
self.last_action_sec = util.gettime()
|
||||
self.last_action_sec = os.time()
|
||||
self:nextTick(self.auto_suspend_action)
|
||||
end
|
||||
dbg:guard(UIManager, '_startAutoSuspend',
|
||||
@@ -772,7 +772,7 @@ function UIManager:_initAutoSuspend()
|
||||
end
|
||||
|
||||
function UIManager:_resetAutoSuspendTimer()
|
||||
self.last_action_sec = util.gettime()
|
||||
self.last_action_sec = os.time()
|
||||
end
|
||||
|
||||
self:_startAutoSuspend()
|
||||
|
||||
@@ -91,7 +91,6 @@ function Usage:dumpCharging(kv_pairs)
|
||||
end
|
||||
|
||||
local BatteryStat = {
|
||||
name = "batterstat",
|
||||
settings = LuaSettings:open(DataStorage:getSettingsDir() .. "/batterstat.lua"),
|
||||
dump_file = util.realpath(DataStorage:getDataDir()) .. "/batterystat.log",
|
||||
debugging = false,
|
||||
@@ -201,7 +200,7 @@ function BatteryStat:onNotCharging()
|
||||
self:accumulate()
|
||||
end
|
||||
|
||||
function BatteryStat:onCallback()
|
||||
function BatteryStat:showStatistics()
|
||||
self:initCurrentState()
|
||||
self:accumulate()
|
||||
local kv_pairs = self:dump()
|
||||
@@ -245,7 +244,9 @@ end
|
||||
|
||||
BatteryStat:init()
|
||||
|
||||
local BatteryStatWidget = WidgetContainer:new()
|
||||
local BatteryStatWidget = WidgetContainer:new{
|
||||
name = "batterystat",
|
||||
}
|
||||
|
||||
function BatteryStatWidget:init()
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
@@ -255,7 +256,7 @@ function BatteryStatWidget:addToMainMenu(menu_items)
|
||||
menu_items.battery_statistics = {
|
||||
text = _("Battery statistics"),
|
||||
callback = function()
|
||||
BatteryStat:onCallback()
|
||||
BatteryStat:showStatistics()
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
79
plugins/systemstat.koplugin/main.lua
Normal file
79
plugins/systemstat.koplugin/main.lua
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
local KeyValuePage = require("ui/widget/keyvaluepage")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local _ = require("gettext")
|
||||
|
||||
local SystemStat = {
|
||||
start_sec = os.time(),
|
||||
wakeup_count = 0,
|
||||
sleep_count = 0,
|
||||
charge_count = 0,
|
||||
discharge_count = 0,
|
||||
}
|
||||
|
||||
function SystemStat:onSuspend()
|
||||
self.sleep_count = self.sleep_count + 1
|
||||
end
|
||||
|
||||
function SystemStat:onResume()
|
||||
self.wakeup_count = self.wakeup_count + 1
|
||||
end
|
||||
|
||||
function SystemStat:onCharging()
|
||||
self.charge_count = self.charge_count + 1
|
||||
end
|
||||
|
||||
function SystemStat:onNotCharging()
|
||||
self.discharge_count = self.discharge_count + 1
|
||||
end
|
||||
|
||||
function SystemStat:showStatistics()
|
||||
local kv_pairs = {
|
||||
{_("KOReader Started at"), os.date("%c", self.start_sec)},
|
||||
{_("Up hours"), string.format("%.2f", os.difftime(os.time(), self.start_sec) / 60 / 60)},
|
||||
{_("Number of wake-ups"), self.wakeup_count},
|
||||
{_("Number of sleeps"), self.sleep_count},
|
||||
{_("Number of charge cycles"), self.charge_count},
|
||||
{_("Number of discharge cycles"), self.discharge_count},
|
||||
}
|
||||
UIManager:show(KeyValuePage:new{
|
||||
title = _("System statistics"),
|
||||
kv_pairs = kv_pairs,
|
||||
})
|
||||
end
|
||||
|
||||
local SystemStatWidget = WidgetContainer:new{
|
||||
name = "systemstat",
|
||||
}
|
||||
|
||||
function SystemStatWidget:init()
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
|
||||
function SystemStatWidget:addToMainMenu(menu_items)
|
||||
menu_items.system_statistics = {
|
||||
text = _("System statistics"),
|
||||
callback = function()
|
||||
SystemStat:showStatistics()
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
function SystemStatWidget:onSuspend()
|
||||
SystemStat:onSuspend()
|
||||
end
|
||||
|
||||
function SystemStatWidget:onResume()
|
||||
SystemStat:onResume()
|
||||
end
|
||||
|
||||
function SystemStatWidget:onCharging()
|
||||
SystemStat:onCharging()
|
||||
end
|
||||
|
||||
function SystemStatWidget:onNotCharging()
|
||||
SystemStat:onNotCharging()
|
||||
end
|
||||
|
||||
return SystemStatWidget
|
||||
Reference in New Issue
Block a user