mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
PowerD: Prevent potential dependency loop in get*Capacity
Not currently happening in vanilla code, but, not entirely unlikely. stateChanged already uses a similar guard. Re https://github.com/koreader/koreader/pull/8672#discussion_r790126388
This commit is contained in:
@@ -150,10 +150,15 @@ function BasePowerD:setIntensity(intensity)
|
||||
end
|
||||
|
||||
function BasePowerD:getCapacity()
|
||||
-- NOTE: UIManager *should* be loaded at this point.
|
||||
-- If that doesn't hold, c.f., :stateChanged below.
|
||||
local UIManager = require("ui/uimanager")
|
||||
local now_ts = UIManager:getTime()
|
||||
-- BasePowerD is loaded before UIManager.
|
||||
-- Nothing *currently* calls this before UIManager is actually loaded, but future-proof this anyway.
|
||||
local now_ts
|
||||
if package.loaded["ui/uimanager"] ~= nil then
|
||||
local UIManager = require("ui/uimanager")
|
||||
now_ts = UIManager:getTime()
|
||||
else
|
||||
now_ts = TimeVal:now()
|
||||
end
|
||||
|
||||
if (now_ts - self.last_aux_capacity_pull_time):tonumber() >= 60 then
|
||||
self.batt_capacity = self:getCapacityHW()
|
||||
@@ -167,8 +172,13 @@ function BasePowerD:isCharging()
|
||||
end
|
||||
|
||||
function BasePowerD:getAuxCapacity()
|
||||
local UIManager = require("ui/uimanager")
|
||||
local now_ts = UIManager:getTime()
|
||||
local now_ts
|
||||
if package.loaded["ui/uimanager"] ~= nil then
|
||||
local UIManager = require("ui/uimanager")
|
||||
now_ts = UIManager:getTime()
|
||||
else
|
||||
now_ts = TimeVal:now()
|
||||
end
|
||||
|
||||
if (now_ts - self.last_aux_capacity_pull_time):tonumber() >= 60 then
|
||||
local aux_batt_capa = self:getAuxCapacityHW()
|
||||
|
||||
Reference in New Issue
Block a user