Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2017-03-24 06:36:15 +00:00
|
|
|
local DataStorage = require("datastorage")
|
2021-08-30 03:03:56 +00:00
|
|
|
local Dispatcher = require("dispatcher")
|
2017-03-24 06:36:15 +00:00
|
|
|
local KeyValuePage = require("ui/widget/keyvaluepage")
|
|
|
|
local LuaSettings = require("luasettings")
|
|
|
|
local PowerD = require("device"):getPowerDevice()
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2022-11-17 04:53:35 +00:00
|
|
|
local datetime = require("datetime")
|
2017-05-16 09:11:11 +00:00
|
|
|
local dbg = require("dbg")
|
2022-06-27 19:16:51 +00:00
|
|
|
local time = require("ui/time")
|
2017-03-24 06:36:15 +00:00
|
|
|
local _ = require("gettext")
|
2022-11-22 19:09:08 +00:00
|
|
|
local T = require("ffi/util").template
|
2017-03-24 06:36:15 +00:00
|
|
|
|
|
|
|
local State = {}
|
|
|
|
|
|
|
|
function State:new(o)
|
|
|
|
o = o or {}
|
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
if o.percentage == nil or o.timestamp == nil then
|
2017-06-24 14:53:20 +00:00
|
|
|
o.percentage = PowerD:getCapacityHW()
|
2022-06-27 19:16:51 +00:00
|
|
|
o.timestamp = time.boottime_or_realtime_coarse()
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
function State:toString()
|
2022-06-27 19:16:51 +00:00
|
|
|
return string.format("{%d @ %s}", self.percentage, os.date("%c", time.to_s(self.timestamp)))
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local Usage = {}
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
local INDENTATION = " " -- Three spaces.
|
2017-03-24 06:36:15 +00:00
|
|
|
|
|
|
|
function Usage:new(o)
|
|
|
|
o = o or {}
|
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
if o.percentage == nil or o.time == nil then
|
|
|
|
o.percentage = 0
|
|
|
|
o.time = 0
|
|
|
|
end
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:append(state)
|
|
|
|
local curr = State:new()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self.percentage = self.percentage + math.abs(state.percentage - curr.percentage)
|
2022-06-27 19:16:51 +00:00
|
|
|
self.time = self.time + curr.timestamp - state.timestamp
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
2022-01-19 08:42:13 +00:00
|
|
|
function Usage:percentageRate()
|
2017-03-24 06:36:15 +00:00
|
|
|
if self.time == 0 then
|
|
|
|
return 0
|
|
|
|
else
|
2022-06-27 19:16:51 +00:00
|
|
|
return self.percentage / time.to_s(self.time)
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-19 08:42:13 +00:00
|
|
|
function Usage:percentageRatePerHour()
|
2022-01-19 17:31:58 +00:00
|
|
|
return self:percentageRate() * 3600
|
2022-01-19 08:42:13 +00:00
|
|
|
end
|
|
|
|
|
2021-12-01 11:39:48 +00:00
|
|
|
function Usage:remainingTime()
|
2022-01-19 08:42:13 +00:00
|
|
|
if self:percentageRate() == 0 then return "N/A" end
|
2017-03-24 06:36:15 +00:00
|
|
|
local curr = State:new()
|
2022-01-19 08:42:13 +00:00
|
|
|
return curr.percentage / self:percentageRate()
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
2021-12-01 11:39:48 +00:00
|
|
|
function Usage:chargingTime()
|
2022-01-19 08:42:13 +00:00
|
|
|
if self:percentageRate() == 0 then return "N/A" end
|
2017-03-24 06:36:15 +00:00
|
|
|
local curr = State:new()
|
2022-01-19 08:42:13 +00:00
|
|
|
return math.abs(curr.percentage - 100) / self:percentageRate()
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function shorten(number)
|
2021-02-20 19:15:43 +00:00
|
|
|
if number == "N/A" then return _("N/A") end
|
2021-12-01 11:39:48 +00:00
|
|
|
return string.format("%.2f%%", number)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function duration(number)
|
|
|
|
local duration_fmt = G_reader_settings:readSetting("duration_format", "classic")
|
|
|
|
return type(number) ~= "number" and number or
|
2023-02-12 22:22:11 +00:00
|
|
|
datetime.secondsToClockDuration(duration_fmt, number, true, true)
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
2020-09-12 09:08:26 +00:00
|
|
|
function Usage:dump(kv_pairs, id)
|
2021-12-01 11:39:48 +00:00
|
|
|
local name = id or _("Consumed:")
|
2022-06-27 19:16:51 +00:00
|
|
|
table.insert(kv_pairs, {INDENTATION .. _("Total time:"), duration(time.to_s(self.time)) })
|
2021-12-01 11:39:48 +00:00
|
|
|
table.insert(kv_pairs, {INDENTATION .. name, shorten(self.percentage), "%"})
|
2021-12-26 13:12:42 +00:00
|
|
|
table.insert(kv_pairs, {INDENTATION .. _("Change per hour:"), shorten(self:percentageRatePerHour())})
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:dumpRemaining(kv_pairs)
|
2021-12-01 11:39:48 +00:00
|
|
|
table.insert(kv_pairs, {INDENTATION .. _("Estimated remaining time:"), duration(self:remainingTime())})
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:dumpCharging(kv_pairs)
|
2021-12-01 11:39:48 +00:00
|
|
|
table.insert(kv_pairs, {INDENTATION .. _("Estimated time for charging:"), duration(self:chargingTime())})
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local BatteryStat = {
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
settings = LuaSettings:open(DataStorage:getSettingsDir() .. "/battery_stats.lua"),
|
2017-05-16 09:11:11 +00:00
|
|
|
kv_page = nil,
|
2017-03-24 06:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function BatteryStat:init()
|
|
|
|
self.awake = Usage:new(self.settings:readSetting("awake"))
|
|
|
|
self.sleeping = Usage:new(self.settings:readSetting("sleeping"))
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self.charging = Usage:new(self.settings:readSetting("charging"))
|
|
|
|
self.discharging = Usage:new(self.settings:readSetting("discharging"))
|
2017-03-24 06:36:15 +00:00
|
|
|
|
|
|
|
-- Note: these fields are not the "real" timestamp and battery usage, but
|
|
|
|
-- the unaccumulated values.
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self.awake_state = State:new()
|
|
|
|
self.charging_state = State:new()
|
|
|
|
|
2017-05-31 18:31:27 +00:00
|
|
|
-- Whether the device was suspending before current timestamp.
|
|
|
|
self.was_suspending = false
|
|
|
|
-- Whether the device was charging before current timestamp.
|
|
|
|
self.was_charging = PowerD:isCharging()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
if self.was_charging then
|
|
|
|
self:reset(true, false)
|
|
|
|
end
|
|
|
|
-- Check if the battery was charging when KO was turned off.
|
|
|
|
local battery_before_off = self.settings:readSetting("awake_state")
|
|
|
|
if battery_before_off and battery_before_off.percentage
|
|
|
|
and self.awake_state.percentage > battery_before_off.percentage then
|
|
|
|
self:reset(false, true)
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onFlushSettings()
|
|
|
|
self.settings:reset({
|
|
|
|
charging = self.charging,
|
2017-05-16 09:11:11 +00:00
|
|
|
discharging = self.discharging,
|
2017-03-24 06:36:15 +00:00
|
|
|
awake = self.awake,
|
|
|
|
sleeping = self.sleeping,
|
|
|
|
charging_state = self.charging_state,
|
|
|
|
awake_state = self.awake_state,
|
|
|
|
})
|
|
|
|
self.settings:flush()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:accumulate()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
if self.was_suspending and not self.was_charging then
|
2017-03-24 06:36:15 +00:00
|
|
|
-- Suspending to awake.
|
|
|
|
self.sleeping:append(self.awake_state)
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
elseif not self.was_suspending and not self.was_charging then
|
2017-03-24 06:36:15 +00:00
|
|
|
-- Awake to suspending, time between self.awake_state and now should belong to awake.
|
|
|
|
self.awake:append(self.awake_state)
|
|
|
|
end
|
|
|
|
if self.was_charging then
|
|
|
|
-- Decharging to charging.
|
|
|
|
self.charging:append(self.charging_state)
|
|
|
|
else
|
2017-05-16 09:11:11 +00:00
|
|
|
self.discharging:append(self.charging_state)
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
self.awake_state = State:new()
|
|
|
|
self.charging_state = State:new()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onSuspend()
|
2017-08-08 06:29:57 +00:00
|
|
|
if not self.was_suspending then
|
|
|
|
self:accumulate()
|
|
|
|
end
|
|
|
|
self.was_suspending = true
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onResume()
|
2017-08-08 06:29:57 +00:00
|
|
|
if self.was_suspending then
|
|
|
|
self:accumulate()
|
|
|
|
end
|
|
|
|
self.was_suspending = false
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onCharging()
|
2017-08-08 06:29:57 +00:00
|
|
|
if not self.was_charging then
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self:reset(true, true)
|
2017-08-08 06:29:57 +00:00
|
|
|
self:accumulate()
|
|
|
|
end
|
|
|
|
self.was_charging = true
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onNotCharging()
|
2017-08-08 06:29:57 +00:00
|
|
|
if self.was_charging then
|
|
|
|
self:reset(false, true)
|
|
|
|
self:accumulate()
|
|
|
|
end
|
|
|
|
self.was_charging = false
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
2017-04-02 21:46:19 +00:00
|
|
|
function BatteryStat:showStatistics()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
local function askResetData()
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = _("Are you sure that you want to clear battery statistics?"),
|
|
|
|
ok_text = _("Clear"),
|
|
|
|
ok_callback = function()
|
|
|
|
self:resetAll()
|
|
|
|
self:restart()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-03-24 06:36:15 +00:00
|
|
|
self:accumulate()
|
|
|
|
local kv_pairs = self:dump()
|
2021-02-20 19:15:43 +00:00
|
|
|
kv_pairs[#kv_pairs].separator = true
|
2021-12-01 11:39:48 +00:00
|
|
|
table.insert(kv_pairs, {_("Tap to reset the data."), "",
|
2017-05-16 09:11:11 +00:00
|
|
|
callback = function()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
UIManager:setDirty(self.kv_page, "fast")
|
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
askResetData()
|
|
|
|
end)
|
2017-05-16 09:11:11 +00:00
|
|
|
end})
|
|
|
|
self.kv_page = KeyValuePage:new{
|
2022-11-22 19:09:08 +00:00
|
|
|
title = T(_("Battery statistics (now %1%)"), self.awake_state.percentage),
|
2017-03-24 06:36:15 +00:00
|
|
|
kv_pairs = kv_pairs,
|
2021-12-01 11:39:48 +00:00
|
|
|
single_page = true,
|
2017-05-16 09:11:11 +00:00
|
|
|
}
|
|
|
|
UIManager:show(self.kv_page)
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:reset(withCharging, withDischarging)
|
|
|
|
self.awake = Usage:new()
|
|
|
|
self.sleeping = Usage:new()
|
|
|
|
|
|
|
|
if withCharging then
|
|
|
|
self.charging = Usage:new()
|
|
|
|
end
|
|
|
|
if withDischarging then
|
|
|
|
self.discharging = Usage:new()
|
|
|
|
end
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self.awake_state = State:new()
|
2017-05-16 09:11:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:resetAll()
|
|
|
|
self:reset(true, true)
|
|
|
|
self.charging_state = State:new()
|
|
|
|
self.awake_state = State:new()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:restart()
|
|
|
|
dbg.dassert(self.kv_page ~= nil)
|
|
|
|
UIManager:close(self.kv_page)
|
|
|
|
self:showStatistics()
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:dump()
|
|
|
|
local kv_pairs = {}
|
|
|
|
table.insert(kv_pairs, {_("Awake since last charge"), ""})
|
|
|
|
self.awake:dump(kv_pairs)
|
|
|
|
self.awake:dumpRemaining(kv_pairs)
|
|
|
|
table.insert(kv_pairs, {_("Sleeping since last charge"), ""})
|
|
|
|
self.sleeping:dump(kv_pairs)
|
|
|
|
self.sleeping:dumpRemaining(kv_pairs)
|
|
|
|
table.insert(kv_pairs, {_("During last charge"), ""})
|
2021-12-01 11:39:48 +00:00
|
|
|
self.charging:dump(kv_pairs, _("Charged:"))
|
2017-03-24 06:36:15 +00:00
|
|
|
self.charging:dumpCharging(kv_pairs)
|
|
|
|
table.insert(kv_pairs, {_("Since last charge"), ""})
|
2017-05-16 09:11:11 +00:00
|
|
|
self.discharging:dump(kv_pairs)
|
|
|
|
self.discharging:dumpRemaining(kv_pairs)
|
2017-03-24 06:36:15 +00:00
|
|
|
return kv_pairs
|
|
|
|
end
|
|
|
|
|
|
|
|
BatteryStat:init()
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local BatteryStatWidget = WidgetContainer:extend{
|
2017-04-02 21:46:19 +00:00
|
|
|
name = "batterystat",
|
|
|
|
}
|
2017-03-24 06:36:15 +00:00
|
|
|
|
2021-08-30 03:03:56 +00:00
|
|
|
function BatteryStatWidget:onDispatcherRegisterActions()
|
|
|
|
Dispatcher:registerAction("battery_statistics", {category="none", event="ShowBatteryStatistics", title=_("Battery statistics"), device=true, separator=true})
|
|
|
|
end
|
|
|
|
|
2017-03-24 06:36:15 +00:00
|
|
|
function BatteryStatWidget:init()
|
2017-08-08 06:29:57 +00:00
|
|
|
-- self.ui is nil in test cases.
|
|
|
|
if not self.ui or not self.ui.menu then return end
|
2021-08-30 03:03:56 +00:00
|
|
|
self:onDispatcherRegisterActions()
|
2017-03-24 06:36:15 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
end
|
|
|
|
|
2017-03-26 09:27:43 +00:00
|
|
|
function BatteryStatWidget:addToMainMenu(menu_items)
|
|
|
|
menu_items.battery_statistics = {
|
2017-03-24 06:36:15 +00:00
|
|
|
text = _("Battery statistics"),
|
2018-09-04 21:55:58 +00:00
|
|
|
keep_menu_open = true,
|
2017-03-24 06:36:15 +00:00
|
|
|
callback = function()
|
2017-04-02 21:46:19 +00:00
|
|
|
BatteryStat:showStatistics()
|
2017-03-24 06:36:15 +00:00
|
|
|
end,
|
2017-03-26 10:57:47 +00:00
|
|
|
}
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
2021-08-30 03:03:56 +00:00
|
|
|
function BatteryStatWidget:onShowBatteryStatistics()
|
|
|
|
BatteryStat:showStatistics()
|
|
|
|
end
|
|
|
|
|
2017-03-24 06:36:15 +00:00
|
|
|
function BatteryStatWidget:onFlushSettings()
|
|
|
|
BatteryStat:onFlushSettings()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStatWidget:onSuspend()
|
|
|
|
BatteryStat:onSuspend()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStatWidget:onResume()
|
|
|
|
BatteryStat:onResume()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStatWidget:onCharging()
|
|
|
|
BatteryStat:onCharging()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStatWidget:onNotCharging()
|
|
|
|
BatteryStat:onNotCharging()
|
|
|
|
end
|
|
|
|
|
2017-08-08 06:29:57 +00:00
|
|
|
-- Test only
|
|
|
|
function BatteryStatWidget:stat()
|
|
|
|
return BatteryStat
|
|
|
|
end
|
|
|
|
|
2017-03-24 06:36:15 +00:00
|
|
|
return BatteryStatWidget
|