2021-06-29 12:07:29 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2018-08-11 20:47:33 +00:00
|
|
|
local Device = require("device")
|
2021-06-29 12:07:29 +00:00
|
|
|
local Event = require("ui/event")
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local SpinWidget = require("ui/widget/spinwidget")
|
2018-08-11 20:47:33 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
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 WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2018-08-11 20:47:33 +00:00
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
local _ = require("gettext")
|
2022-05-23 22:25:50 +00:00
|
|
|
local C_ = _.pgettext
|
2018-08-11 20:47:33 +00:00
|
|
|
local T = require("ffi/util").template
|
|
|
|
|
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 ReaderDeviceStatus = WidgetContainer:extend{
|
2022-05-09 16:23:50 +00:00
|
|
|
battery_confirm_box = nil,
|
|
|
|
memory_confirm_box = nil,
|
2018-08-11 20:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderDeviceStatus:init()
|
2021-08-13 22:00:47 +00:00
|
|
|
if Device:hasBattery() then
|
2022-05-05 19:00:22 +00:00
|
|
|
self.battery_interval_m = G_reader_settings:readSetting("device_status_battery_interval_minutes", 10)
|
2021-09-08 13:50:20 +00:00
|
|
|
self.battery_threshold = G_reader_settings:readSetting("device_status_battery_threshold", 20)
|
|
|
|
self.battery_threshold_high = G_reader_settings:readSetting("device_status_battery_threshold_high", 100)
|
2022-05-09 16:23:50 +00:00
|
|
|
-- `checkLowBatteryLevel` and `checkHighMemoryUsage` are each supposed to start one second past the top of the minute,
|
|
|
|
-- as some other periodic activities do (e.g. footer). This means that the processor is woken up less often from standby.
|
|
|
|
self.checkLowBatteryLevel = function(sync)
|
2021-08-13 22:00:47 +00:00
|
|
|
local is_charging = powerd:isCharging()
|
2018-08-11 20:47:33 +00:00
|
|
|
local battery_capacity = powerd:getCapacity()
|
2021-08-13 22:00:47 +00:00
|
|
|
if powerd:getDismissBatteryStatus() == true then -- alerts dismissed
|
|
|
|
if (is_charging and battery_capacity <= self.battery_threshold_high) or
|
|
|
|
(not is_charging and battery_capacity > self.battery_threshold) then
|
|
|
|
powerd:setDismissBatteryStatus(false)
|
|
|
|
end
|
|
|
|
else
|
2021-08-17 13:22:31 +00:00
|
|
|
if (is_charging and battery_capacity > self.battery_threshold_high) or
|
|
|
|
(not is_charging and battery_capacity <= self.battery_threshold) then
|
|
|
|
if self.battery_confirm_box then
|
|
|
|
UIManager:close(self.battery_confirm_box)
|
|
|
|
end
|
|
|
|
self.battery_confirm_box = ConfirmBox:new {
|
2022-05-23 22:25:50 +00:00
|
|
|
text = is_charging and T(_("High battery level: %1 %\n\nDismiss battery level alert?"), battery_capacity)
|
|
|
|
or T(_("Low battery level: %1 %\n\nDismiss battery level alert?"), battery_capacity),
|
2021-08-13 22:00:47 +00:00
|
|
|
ok_text = _("Dismiss"),
|
|
|
|
dismissable = false,
|
|
|
|
ok_callback = function()
|
|
|
|
powerd:setDismissBatteryStatus(true)
|
|
|
|
end,
|
2021-08-17 13:22:31 +00:00
|
|
|
}
|
|
|
|
UIManager:show(self.battery_confirm_box)
|
2021-08-13 22:00:47 +00:00
|
|
|
end
|
2018-08-11 20:47:33 +00:00
|
|
|
end
|
2022-05-09 16:23:50 +00:00
|
|
|
local offset = sync and (os.date("%S") - 1) or 0
|
|
|
|
UIManager:scheduleIn(self.battery_interval_m * 60 - offset, self.checkLowBatteryLevel)
|
2018-08-11 20:47:33 +00:00
|
|
|
end
|
|
|
|
self:startBatteryChecker()
|
|
|
|
end
|
2021-06-29 12:07:29 +00:00
|
|
|
|
|
|
|
if not Device:isAndroid() then
|
2022-05-05 19:00:22 +00:00
|
|
|
self.memory_interval_m = G_reader_settings:readSetting("device_status_memory_interval_minutes", 5)
|
2021-09-08 13:50:20 +00:00
|
|
|
self.memory_threshold = G_reader_settings:readSetting("device_status_memory_threshold", 100)
|
2022-05-09 16:23:50 +00:00
|
|
|
-- `checkLowBatteryLevel` and `checkHighMemoryUsage` are each supposed to start one second past the top of the minute,
|
|
|
|
-- as some other periodic activities do (e.g. footer). This means that the processor is woken up less often from standby.
|
|
|
|
self.checkHighMemoryUsage = function(sync)
|
2021-06-29 12:07:29 +00:00
|
|
|
local statm = io.open("/proc/self/statm", "r")
|
|
|
|
if statm then
|
|
|
|
local dummy, rss = statm:read("*number", "*number")
|
|
|
|
statm:close()
|
2022-10-10 20:21:27 +00:00
|
|
|
rss = math.floor(rss * (4096 / 1024 / 1024))
|
2021-06-29 12:07:29 +00:00
|
|
|
if rss >= self.memory_threshold then
|
2021-08-17 13:22:31 +00:00
|
|
|
if self.memory_confirm_box then
|
|
|
|
UIManager:close(self.memory_confirm_box)
|
|
|
|
end
|
2021-06-29 12:07:29 +00:00
|
|
|
if Device:canRestart() then
|
|
|
|
if UIManager:getTopWidget() == "ReaderUI"
|
|
|
|
and G_reader_settings:isTrue("device_status_memory_auto_restart") then
|
|
|
|
UIManager:show(InfoMessage:new{
|
2021-06-30 18:46:13 +00:00
|
|
|
text = _("High memory usage!\n\nKOReader is restarting…"),
|
2021-06-29 12:07:29 +00:00
|
|
|
icon = "notice-warning",
|
|
|
|
})
|
|
|
|
UIManager:nextTick(function()
|
|
|
|
self.ui:handleEvent(Event:new("Restart"))
|
|
|
|
end)
|
|
|
|
else
|
2021-08-17 13:22:31 +00:00
|
|
|
self.memory_confirm_box = ConfirmBox:new {
|
2021-06-29 12:07:29 +00:00
|
|
|
text = T(_("High memory usage: %1 MB\n\nRestart KOReader?"), rss),
|
|
|
|
ok_text = _("Restart"),
|
|
|
|
dismissable = false,
|
|
|
|
ok_callback = function()
|
|
|
|
UIManager:show(InfoMessage:new{
|
2021-06-30 18:46:13 +00:00
|
|
|
text = _("High memory usage!\n\nKOReader is restarting…"),
|
2021-06-29 12:07:29 +00:00
|
|
|
icon = "notice-warning",
|
|
|
|
})
|
|
|
|
UIManager:nextTick(function()
|
|
|
|
self.ui:handleEvent(Event:new("Restart"))
|
|
|
|
end)
|
|
|
|
end,
|
2021-08-17 13:22:31 +00:00
|
|
|
}
|
|
|
|
UIManager:show(self.memory_confirm_box)
|
2021-06-29 12:07:29 +00:00
|
|
|
end
|
|
|
|
else
|
2021-08-17 13:22:31 +00:00
|
|
|
self.memory_confirm_box = ConfirmBox:new {
|
2021-06-29 12:07:29 +00:00
|
|
|
text = T(_("High memory usage: %1 MB\n\nExit KOReader?"), rss),
|
|
|
|
ok_text = _("Exit"),
|
|
|
|
dismissable = false,
|
|
|
|
ok_callback = function()
|
|
|
|
self.ui:handleEvent(Event:new("Exit"))
|
|
|
|
end,
|
2021-08-17 13:22:31 +00:00
|
|
|
}
|
|
|
|
UIManager:show(self.memory_confirm_box)
|
2021-06-29 12:07:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-05-09 16:23:50 +00:00
|
|
|
local offset = sync and (os.date("%S") - 1) or 0
|
|
|
|
UIManager:scheduleIn(self.memory_interval_m * 60 - offset, self.checkHighMemoryUsage)
|
2021-06-29 12:07:29 +00:00
|
|
|
end
|
|
|
|
self:startMemoryChecker()
|
|
|
|
end
|
|
|
|
|
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
end
|
2018-08-11 20:47:33 +00:00
|
|
|
|
|
|
|
function ReaderDeviceStatus:addToMainMenu(menu_items)
|
2021-06-29 12:07:29 +00:00
|
|
|
menu_items.device_status_alarm = {
|
2021-06-29 19:36:43 +00:00
|
|
|
text = _("Device status alerts"),
|
2021-06-29 12:07:29 +00:00
|
|
|
sub_item_table = {},
|
|
|
|
}
|
2021-08-13 22:00:47 +00:00
|
|
|
if Device:hasBattery() then
|
2021-06-29 12:07:29 +00:00
|
|
|
table.insert(menu_items.device_status_alarm.sub_item_table,
|
2018-08-11 20:47:33 +00:00
|
|
|
{
|
2021-08-13 22:00:47 +00:00
|
|
|
text = _("Battery level"),
|
2018-08-11 20:47:33 +00:00
|
|
|
checked_func = function()
|
2021-06-29 12:07:29 +00:00
|
|
|
return G_reader_settings:isTrue("device_status_battery_alarm")
|
2018-08-11 20:47:33 +00:00
|
|
|
end,
|
|
|
|
callback = function()
|
2021-06-29 12:07:29 +00:00
|
|
|
G_reader_settings:flipNilOrFalse("device_status_battery_alarm")
|
|
|
|
if G_reader_settings:isTrue("device_status_battery_alarm") then
|
2022-05-09 16:23:50 +00:00
|
|
|
self:startBatteryChecker(true)
|
2018-08-11 20:47:33 +00:00
|
|
|
else
|
|
|
|
self:stopBatteryChecker()
|
2021-06-29 12:07:29 +00:00
|
|
|
powerd:setDismissBatteryStatus(false)
|
2018-08-11 20:47:33 +00:00
|
|
|
end
|
|
|
|
end,
|
2021-06-29 12:07:29 +00:00
|
|
|
})
|
|
|
|
table.insert(menu_items.device_status_alarm.sub_item_table,
|
2018-08-11 20:47:33 +00:00
|
|
|
{
|
2021-06-29 12:07:29 +00:00
|
|
|
text_func = function()
|
2022-05-05 19:00:22 +00:00
|
|
|
return T(_("Check interval: %1 min"), self.battery_interval_m)
|
2021-06-29 12:07:29 +00:00
|
|
|
end,
|
|
|
|
enabled_func = function()
|
|
|
|
return G_reader_settings:isTrue("device_status_battery_alarm")
|
|
|
|
end,
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = function(touchmenu_instance)
|
|
|
|
UIManager:show(SpinWidget:new{
|
2022-05-05 19:00:22 +00:00
|
|
|
value = self.battery_interval_m,
|
2021-06-29 12:07:29 +00:00
|
|
|
value_min = 1,
|
|
|
|
value_max = 60,
|
|
|
|
default_value = 10,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Time", "min"),
|
2021-06-29 12:07:29 +00:00
|
|
|
value_hold_step = 5,
|
|
|
|
title_text = _("Battery check interval"),
|
|
|
|
callback = function(spin)
|
2022-05-05 19:00:22 +00:00
|
|
|
self.battery_interval_m = spin.value
|
|
|
|
G_reader_settings:saveSetting("device_status_battery_interval_minutes", self.battery_interval_m)
|
2021-06-29 12:07:29 +00:00
|
|
|
touchmenu_instance:updateItems()
|
|
|
|
powerd:setDismissBatteryStatus(false)
|
2022-05-09 16:23:50 +00:00
|
|
|
self:stopBatteryChecker()
|
|
|
|
-- schedule first check on a full minute to reduce wakeups from standby)
|
|
|
|
UIManager:scheduleIn(self.battery_interval_m * 60 - os.date("%S") + 1,
|
|
|
|
self.checkLowBatteryLevel)
|
2021-06-29 12:07:29 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
table.insert(menu_items.device_status_alarm.sub_item_table,
|
|
|
|
{
|
|
|
|
text_func = function()
|
2022-05-23 22:25:50 +00:00
|
|
|
return T(_("Thresholds: %1 % / %2 %"), self.battery_threshold, self.battery_threshold_high)
|
2021-06-29 12:07:29 +00:00
|
|
|
end,
|
|
|
|
enabled_func = function()
|
|
|
|
return G_reader_settings:isTrue("device_status_battery_alarm")
|
|
|
|
end,
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = function(touchmenu_instance)
|
2021-08-13 22:00:47 +00:00
|
|
|
local DoubleSpinWidget = require("/ui/widget/doublespinwidget")
|
2021-12-01 11:42:54 +00:00
|
|
|
local thresholds_widget
|
|
|
|
thresholds_widget = DoubleSpinWidget:new{
|
2021-08-13 22:00:47 +00:00
|
|
|
title_text = _("Battery level alert thresholds"),
|
|
|
|
info_text = _([[
|
|
|
|
Low level threshold is checked when the device is not charging.
|
|
|
|
High level threshold is checked when the device is charging.]]),
|
|
|
|
left_text = _("Low"),
|
|
|
|
left_value = self.battery_threshold,
|
|
|
|
left_min = 1,
|
|
|
|
left_max = self.battery_threshold_high,
|
|
|
|
left_default = 20,
|
|
|
|
left_hold_step = 5,
|
|
|
|
right_text = _("High"),
|
|
|
|
right_value = self.battery_threshold_high,
|
|
|
|
right_min = self.battery_threshold,
|
|
|
|
right_max = 100,
|
|
|
|
right_default = 100,
|
|
|
|
right_hold_step = 5,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = "%",
|
2021-08-13 22:00:47 +00:00
|
|
|
callback = function(left_value, right_value)
|
|
|
|
self.battery_threshold = left_value
|
|
|
|
self.battery_threshold_high = right_value
|
2021-06-29 12:07:29 +00:00
|
|
|
G_reader_settings:saveSetting("device_status_battery_threshold", self.battery_threshold)
|
2021-08-13 22:00:47 +00:00
|
|
|
G_reader_settings:saveSetting("device_status_battery_threshold_high", self.battery_threshold_high)
|
2021-06-29 12:07:29 +00:00
|
|
|
touchmenu_instance:updateItems()
|
|
|
|
powerd:setDismissBatteryStatus(false)
|
|
|
|
end,
|
2021-08-13 22:00:47 +00:00
|
|
|
}
|
|
|
|
UIManager:show(thresholds_widget)
|
2021-06-29 12:07:29 +00:00
|
|
|
end,
|
|
|
|
separator = true,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
if not Device:isAndroid() then
|
|
|
|
table.insert(menu_items.device_status_alarm.sub_item_table,
|
|
|
|
{
|
|
|
|
text = _("High memory usage"),
|
|
|
|
checked_func = function()
|
|
|
|
return G_reader_settings:isTrue("device_status_memory_alarm")
|
|
|
|
end,
|
2018-08-11 20:47:33 +00:00
|
|
|
callback = function()
|
2021-06-29 12:07:29 +00:00
|
|
|
G_reader_settings:flipNilOrFalse("device_status_memory_alarm")
|
|
|
|
if G_reader_settings:isTrue("device_status_memory_alarm") then
|
2022-05-09 16:23:50 +00:00
|
|
|
self:startMemoryChecker(true)
|
2021-06-29 12:07:29 +00:00
|
|
|
else
|
|
|
|
self:stopMemoryChecker()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
table.insert(menu_items.device_status_alarm.sub_item_table,
|
|
|
|
{
|
|
|
|
text_func = function()
|
2022-05-05 19:00:22 +00:00
|
|
|
return T(_("Check interval: %1 min"), self.memory_interval_m)
|
2021-06-29 12:07:29 +00:00
|
|
|
end,
|
|
|
|
enabled_func = function()
|
|
|
|
return G_reader_settings:isTrue("device_status_memory_alarm")
|
|
|
|
end,
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = function(touchmenu_instance)
|
|
|
|
UIManager:show(SpinWidget:new{
|
2022-05-05 19:00:22 +00:00
|
|
|
value = self.memory_interval_m,
|
2021-06-29 12:07:29 +00:00
|
|
|
value_min = 1,
|
|
|
|
value_max = 60,
|
|
|
|
default_value = 5,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Time", "min"),
|
2021-06-29 12:07:29 +00:00
|
|
|
value_hold_step = 5,
|
|
|
|
title_text = _("Memory check interval"),
|
|
|
|
callback = function(spin)
|
2022-05-05 19:00:22 +00:00
|
|
|
self.memory_interval_m = spin.value
|
|
|
|
G_reader_settings:saveSetting("device_status_memory_interval_minutes", self.memory_interval_m)
|
2021-06-29 12:07:29 +00:00
|
|
|
touchmenu_instance:updateItems()
|
2022-05-09 16:23:50 +00:00
|
|
|
self:stopMemoryChecker()
|
|
|
|
-- schedule first check on a full minute to reduce wakeups from standby)
|
|
|
|
UIManager:scheduleIn(self.memory_interval_m * 60 - os.date("%S") + 1,
|
|
|
|
self.checkHighMemoryUsage)
|
2021-06-29 12:07:29 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
table.insert(menu_items.device_status_alarm.sub_item_table,
|
|
|
|
{
|
|
|
|
text_func = function()
|
2021-09-08 13:50:20 +00:00
|
|
|
return T(_("Threshold: %1 MB"), self.memory_threshold)
|
2021-06-29 12:07:29 +00:00
|
|
|
end,
|
|
|
|
enabled_func = function()
|
|
|
|
return G_reader_settings:isTrue("device_status_memory_alarm")
|
|
|
|
end,
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = function(touchmenu_instance)
|
|
|
|
UIManager:show(SpinWidget:new{
|
|
|
|
value = self.memory_threshold,
|
|
|
|
value_min = 20,
|
|
|
|
value_max = 500,
|
|
|
|
default_value = 100,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Data storage size", "MB"),
|
2021-06-29 12:07:29 +00:00
|
|
|
value_step = 5,
|
2018-08-11 20:47:33 +00:00
|
|
|
value_hold_step = 10,
|
2021-08-13 22:00:47 +00:00
|
|
|
title_text = _("Memory alert threshold"),
|
2021-06-29 12:07:29 +00:00
|
|
|
callback = function(spin)
|
|
|
|
self.memory_threshold = spin.value
|
|
|
|
G_reader_settings:saveSetting("device_status_memory_threshold", self.memory_threshold)
|
|
|
|
touchmenu_instance:updateItems()
|
|
|
|
end,
|
|
|
|
})
|
2018-08-11 20:47:33 +00:00
|
|
|
end,
|
2021-06-29 12:07:29 +00:00
|
|
|
})
|
|
|
|
table.insert(menu_items.device_status_alarm.sub_item_table,
|
|
|
|
{
|
|
|
|
text = _("Automatic restart"),
|
|
|
|
enabled_func = function()
|
|
|
|
return G_reader_settings:isTrue("device_status_memory_alarm") and Device:canRestart()
|
|
|
|
end,
|
|
|
|
checked_func = function()
|
|
|
|
return G_reader_settings:isTrue("device_status_memory_auto_restart")
|
|
|
|
end,
|
|
|
|
callback = function()
|
|
|
|
G_reader_settings:flipNilOrFalse("device_status_memory_auto_restart")
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
2018-08-11 20:47:33 +00:00
|
|
|
end
|
|
|
|
|
2022-05-09 16:23:50 +00:00
|
|
|
-- `checkLowBatteryLevel` and `checkHighMemoryUsage` are each supposed to start one second past the top of the minute,
|
|
|
|
-- as some other periodic activities do (e.g. footer). This means that the processor is woken up less often from standby.
|
|
|
|
function ReaderDeviceStatus:startBatteryChecker(sync)
|
2021-06-29 12:07:29 +00:00
|
|
|
if G_reader_settings:isTrue("device_status_battery_alarm") then
|
2022-05-09 16:23:50 +00:00
|
|
|
self.checkLowBatteryLevel(sync)
|
2018-08-11 20:47:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDeviceStatus:stopBatteryChecker()
|
2021-06-29 13:41:43 +00:00
|
|
|
if self.checkLowBatteryLevel then
|
|
|
|
UIManager:unschedule(self.checkLowBatteryLevel)
|
|
|
|
end
|
2021-06-29 12:07:29 +00:00
|
|
|
end
|
|
|
|
|
2022-05-09 16:23:50 +00:00
|
|
|
-- `checkLowBatteryLevel` and `checkHighMemoryUsage` are each supposed to start one second past the top of the minute,
|
|
|
|
-- as some other periodic activities do (e.g. footer). This means that the processor is woken up less often from standby.
|
|
|
|
function ReaderDeviceStatus:startMemoryChecker(sync)
|
2021-06-29 12:07:29 +00:00
|
|
|
if G_reader_settings:isTrue("device_status_memory_alarm") then
|
2022-05-09 16:23:50 +00:00
|
|
|
self.checkHighMemoryUsage(sync)
|
2018-08-11 20:47:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-29 12:07:29 +00:00
|
|
|
function ReaderDeviceStatus:stopMemoryChecker()
|
2021-06-29 13:41:43 +00:00
|
|
|
if self.checkHighMemoryUsage then
|
|
|
|
UIManager:unschedule(self.checkHighMemoryUsage)
|
|
|
|
end
|
2021-06-29 12:07:29 +00:00
|
|
|
end
|
|
|
|
|
2018-08-11 20:47:33 +00:00
|
|
|
function ReaderDeviceStatus:onResume()
|
2022-05-09 16:23:50 +00:00
|
|
|
self:startBatteryChecker(true)
|
|
|
|
self:startMemoryChecker(true)
|
2018-08-11 20:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDeviceStatus:onSuspend()
|
|
|
|
self:stopBatteryChecker()
|
2021-06-29 12:07:29 +00:00
|
|
|
self:stopMemoryChecker()
|
2018-08-11 20:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDeviceStatus:onCloseWidget()
|
|
|
|
self:stopBatteryChecker()
|
2021-06-29 12:07:29 +00:00
|
|
|
self:stopMemoryChecker()
|
2018-08-11 20:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return ReaderDeviceStatus
|