Restart KOReader: add a ConfirmBox instead of a plain InfoMessage (#9853)

This commit is contained in:
zwim
2022-12-03 21:29:13 +01:00
committed by GitHub
parent fa9f0acf5e
commit d1cd2a1c8d
15 changed files with 67 additions and 95 deletions

View File

@@ -573,10 +573,10 @@ end
-- Set device event handlers common to all devices
function Device:_setEventHandlers(UIManager)
if self:canReboot() then
UIManager.event_handlers.Reboot = function()
UIManager.event_handlers.Reboot = function(message_text)
local ConfirmBox = require("ui/widget/confirmbox")
UIManager:show(ConfirmBox:new{
text = _("Are you sure you want to reboot the device?"),
text = message_text or _("Are you sure you want to reboot the device?"),
ok_text = _("Reboot"),
ok_callback = function()
local Event = require("ui/event")
@@ -590,10 +590,10 @@ function Device:_setEventHandlers(UIManager)
end
if self:canPowerOff() then
UIManager.event_handlers.PowerOff = function()
UIManager.event_handlers.PowerOff = function(message_text)
local ConfirmBox = require("ui/widget/confirmbox")
UIManager:show(ConfirmBox:new{
text = _("Are you sure you want to power off the device?"),
text = message_text or _("Are you sure you want to power off the device?"),
ok_text = _("Power off"),
ok_callback = function()
local Event = require("ui/event")
@@ -606,6 +606,28 @@ function Device:_setEventHandlers(UIManager)
UIManager.event_handlers.PowerOff = function() end
end
if self:canRestart() then
UIManager.event_handlers.Restart = function(message_text)
local ConfirmBox = require("ui/widget/confirmbox")
UIManager:show(ConfirmBox:new{
text = message_text or _("This will take effect on next restart."),
ok_text = _("Restart now"),
ok_callback = function()
local Event = require("ui/event")
UIManager:broadcastEvent(Event:new("Restart"))
end,
cancel_text = _("Restart later"),
})
end
else
UIManager.event_handlers.Restart = function(message_text)
local InfoMessage = require("ui/widget/infomessage")
UIManager:show(InfoMessage:new{
text = message_text or _("This will take effect on next restart."),
})
end
end
self:setEventHandlers(UIManager)
end