ReaderDeviceStatus: show only one alert (#8086)

reviewable/pr8093/r1
hius07 3 years ago committed by GitHub
parent 19f43c47e1
commit a8b39c17ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,6 +11,8 @@ local _ = require("gettext")
local T = require("ffi/util").template local T = require("ffi/util").template
local ReaderDeviceStatus = InputContainer:new{ local ReaderDeviceStatus = InputContainer:new{
battery_confirm_box = nil,
memory_confirm_box = nil,
} }
function ReaderDeviceStatus:init() function ReaderDeviceStatus:init()
@ -27,24 +29,21 @@ function ReaderDeviceStatus:init()
powerd:setDismissBatteryStatus(false) powerd:setDismissBatteryStatus(false)
end end
else else
if is_charging and battery_capacity > self.battery_threshold_high then if (is_charging and battery_capacity > self.battery_threshold_high) or
UIManager:show(ConfirmBox:new { (not is_charging and battery_capacity <= self.battery_threshold) then
text = T(_("High battery level: %1%\n\nDismiss battery level alert?"), battery_capacity), if self.battery_confirm_box then
ok_text = _("Dismiss"), UIManager:close(self.battery_confirm_box)
dismissable = false, end
ok_callback = function() self.battery_confirm_box = ConfirmBox:new {
powerd:setDismissBatteryStatus(true) text = is_charging and T(_("High battery level: %1%\n\nDismiss battery level alert?"), battery_capacity)
end, or T(_("Low battery level: %1%\n\nDismiss battery level alert?"), battery_capacity),
})
elseif not is_charging and battery_capacity <= self.battery_threshold then
UIManager:show(ConfirmBox:new {
text = T(_("Low battery level: %1%\n\nDismiss battery level alert?"), battery_capacity),
ok_text = _("Dismiss"), ok_text = _("Dismiss"),
dismissable = false, dismissable = false,
ok_callback = function() ok_callback = function()
powerd:setDismissBatteryStatus(true) powerd:setDismissBatteryStatus(true)
end, end,
}) }
UIManager:show(self.battery_confirm_box)
end end
end end
UIManager:scheduleIn(self.battery_interval * 60, self.checkLowBatteryLevel) UIManager:scheduleIn(self.battery_interval * 60, self.checkLowBatteryLevel)
@ -62,6 +61,9 @@ function ReaderDeviceStatus:init()
statm:close() statm:close()
rss = math.floor(rss * 4096 / 1024 / 1024) rss = math.floor(rss * 4096 / 1024 / 1024)
if rss >= self.memory_threshold then if rss >= self.memory_threshold then
if self.memory_confirm_box then
UIManager:close(self.memory_confirm_box)
end
if Device:canRestart() then if Device:canRestart() then
if UIManager:getTopWidget() == "ReaderUI" if UIManager:getTopWidget() == "ReaderUI"
and G_reader_settings:isTrue("device_status_memory_auto_restart") then and G_reader_settings:isTrue("device_status_memory_auto_restart") then
@ -73,7 +75,7 @@ function ReaderDeviceStatus:init()
self.ui:handleEvent(Event:new("Restart")) self.ui:handleEvent(Event:new("Restart"))
end) end)
else else
UIManager:show(ConfirmBox:new { self.memory_confirm_box = ConfirmBox:new {
text = T(_("High memory usage: %1 MB\n\nRestart KOReader?"), rss), text = T(_("High memory usage: %1 MB\n\nRestart KOReader?"), rss),
ok_text = _("Restart"), ok_text = _("Restart"),
dismissable = false, dismissable = false,
@ -86,17 +88,19 @@ function ReaderDeviceStatus:init()
self.ui:handleEvent(Event:new("Restart")) self.ui:handleEvent(Event:new("Restart"))
end) end)
end, end,
}) }
UIManager:show(self.memory_confirm_box)
end end
else else
UIManager:show(ConfirmBox:new { self.memory_confirm_box = ConfirmBox:new {
text = T(_("High memory usage: %1 MB\n\nExit KOReader?"), rss), text = T(_("High memory usage: %1 MB\n\nExit KOReader?"), rss),
ok_text = _("Exit"), ok_text = _("Exit"),
dismissable = false, dismissable = false,
ok_callback = function() ok_callback = function()
self.ui:handleEvent(Event:new("Exit")) self.ui:handleEvent(Event:new("Exit"))
end, end,
}) }
UIManager:show(self.memory_confirm_box)
end end
end end
end end

Loading…
Cancel
Save