Kobo: Offer to power off if the power button is held for at least 3 seconds

pull/1992/head
Cosmin Gorgovan 8 years ago
parent 18c0cee18f
commit 19338cb439

@ -153,6 +153,9 @@ function Device:suspend() end
-- Hardware specific method to resume the device
function Device:resume() end
-- Hardware specific method to power off the device
function Device:powerOff() end
function Device:usbPlugIn()
if self.charging_mode == false and self.screen_saver_mode == false then
self.screen:saveCurrentBB()

@ -258,20 +258,26 @@ function Input:handleKeyBoardEv(ev)
end
end
if ev.value == EVENT_VALUE_KEY_RELEASE then
if keycode == "Light" then
return keycode
elseif keycode == "Power" then
-- Kobo generates Power keycode only, we need to decide whether it's
-- power-on or power-off ourselves.
if self.device.screen_saver_mode then
if keycode == "Power" then
-- Kobo generates Power keycode only, we need to decide whether it's
-- power-on or power-off ourselves.
if self.device.screen_saver_mode then
if ev.value == EVENT_VALUE_KEY_RELEASE then
return "Resume"
else
return "Suspend"
end
else
if ev.value == EVENT_VALUE_KEY_PRESS then
return "PowerPress"
elseif ev.value == EVENT_VALUE_KEY_RELEASE then
return "PowerRelease"
end
end
end
if ev.value == EVENT_VALUE_KEY_RELEASE and keycode == "Light" then
return keycode
end
-- handle modifier keys
if self.modifiers[keycode] ~= nil then
if ev.value == EVENT_VALUE_KEY_PRESS then

@ -189,6 +189,10 @@ function Kobo:resume()
end
end
function Kobo:powerOff()
os.execute("poweroff")
end
-------------- device probe ------------
local codename = Kobo:getCodeName()

@ -27,6 +27,7 @@ local UIManager = {
_zeromqs = {},
_refresh_stack = {},
_refresh_func_stack = {},
_power_ev_handled = false,
}
function UIManager:init()
@ -55,6 +56,36 @@ function UIManager:init()
self:sendEvent(Event:new("Resume"))
self:_startAutoSuspend()
end
self.event_handlers["PowerPress"] = function(input_event)
self._power_ev_handled = false
local showPowerOffDialog = function()
if self._power_ev_handled then return end
self._power_ev_handled = true
local ConfirmBox = require("ui/widget/confirmbox")
UIManager:show(ConfirmBox:new{
text = _("Power off?"),
ok_callback = function()
local InfoMessage = require("ui/widget/infomessage")
UIManager:show(InfoMessage:new{
text = _("Powered off."),
})
-- The message can fail to render if this is executed directly
UIManager:scheduleIn(0.1, function()
self:broadcastEvent(Event:new("Close"))
Device:powerOff()
end)
end,
})
end
UIManager:scheduleIn(3, showPowerOffDialog)
end
self.event_handlers["PowerRelease"] = function(input_event)
if not self._power_ev_handled then
self._power_ev_handled = true
self.event_handlers["Suspend"]("Suspend")
end
end
self.event_handlers["Light"] = function()
Device:getPowerDevice():toggleFrontlight()
end

Loading…
Cancel
Save