[UX] Add exit menu (#3167)

* fixes #2898 (prevents accidentally triggering reboot or poweroff)
  Add ConfirmBox before reboot/power off
* increases clarity by preventing second page
* add "sleep" menu entry
* Add exit menu hold callback
pull/3169/head
Frans de Jonge 7 years ago committed by GitHub
parent c24d75f18c
commit 177485f84f

@ -266,6 +266,12 @@ function FileManagerMenu:setUpdateItemTable()
for id, common_setting in pairs(require("ui/elements/common_info_menu_table")) do for id, common_setting in pairs(require("ui/elements/common_info_menu_table")) do
self.menu_items[id] = common_setting self.menu_items[id] = common_setting
end end
self.menu_items.exit_menu = {
text = _("Exit"),
hold_callback = function()
self:exitOrRestart()
end,
}
self.menu_items.exit = { self.menu_items.exit = {
text = _("Exit"), text = _("Exit"),
callback = function() callback = function()

@ -184,13 +184,18 @@ function ReaderMenu:setUpdateItemTable()
self.menu_items[id] = common_setting self.menu_items[id] = common_setting
end end
self.menu_items.exit_menu = {
text = _("Exit"),
hold_callback = function()
self:exitOrRestart()
end,
}
self.menu_items.exit = { self.menu_items.exit = {
text = _("Exit"), text = _("Exit"),
callback = function() callback = function()
self:exitOrRestart() self:exitOrRestart()
end, end,
} }
self.menu_items.restart_koreader = { self.menu_items.restart_koreader = {
text = _("Restart KOReader"), text = _("Restart KOReader"),
callback = function() callback = function()

@ -1,3 +1,4 @@
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device") local Device = require("device")
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
@ -52,17 +53,38 @@ common_info.report_bug = {
}) })
end end
} }
if Device:isKindle() or Device:isKobo() then
common_info.sleep = {
text = _("Sleep"),
callback = function()
UIManager:suspend()
end,
}
end
if Device:isKobo() then if Device:isKobo() then
common_info.reboot = { common_info.reboot = {
text = _("Reboot the device"), text = _("Reboot the device"),
callback = function() callback = function()
UIManager:nextTick(UIManager.reboot_action) UIManager:show(ConfirmBox:new{
text = _("Are you sure you want to reboot the device?"),
ok_text = _("Reboot"),
ok_callback = function()
UIManager:nextTick(UIManager.reboot_action)
end,
})
end end
} }
common_info.poweroff = { common_info.poweroff = {
text = _("Power off"), text = _("Power off"),
callback = function() callback = function()
UIManager:nextTick(UIManager.poweroff_action) UIManager:show(ConfirmBox:new{
text = _("Are you sure you want to power off the device?"),
ok_text = _("Power off"),
ok_callback = function()
UIManager:nextTick(UIManager.poweroff_action)
end,
})
end end
} }
end end

@ -68,17 +68,14 @@ local order = {
"history", "history",
"open_last_document", "open_last_document",
"----------------------------", "----------------------------",
"system_statistics",
"----------------------------",
"ota_update", --[[ if Device:isKindle() or Device:isKobo() or "ota_update", --[[ if Device:isKindle() or Device:isKobo() or
Device:isPocketBook() or Device:isAndroid() ]]-- Device:isPocketBook() or Device:isAndroid() ]]--
"version", "version",
"help", "help",
"system_statistics",
"----------------------------",
"restart_koreader",
"poweroff", -- if Device:isKobo()
"reboot", -- if Device:isKobo()
"----------------------------", "----------------------------",
"exit", "exit_menu",
}, },
help = { help = {
"quickstart_guide", "quickstart_guide",
@ -87,6 +84,15 @@ local order = {
"----------------------------", "----------------------------",
"about", "about",
}, },
exit_menu = {
"restart_koreader",
"----------------------------",
"sleep", -- if Device:isKindle() or Device:isKobo()
"poweroff", -- if Device:isKobo()
"reboot", -- if Device:isKobo()
"----------------------------",
"exit",
}
} }
return order return order

@ -85,17 +85,14 @@ local order = {
"book_status", "book_status",
"book_info", "book_info",
"----------------------------", "----------------------------",
"system_statistics",
"----------------------------",
"ota_update", --[[ if Device:isKindle() or Device:isKobo() or "ota_update", --[[ if Device:isKindle() or Device:isKobo() or
Device:isPocketBook() or Device:isAndroid() ]]-- Device:isPocketBook() or Device:isAndroid() ]]--
"version", "version",
"help", "help",
"system_statistics",
"----------------------------",
"restart_koreader",
"poweroff", -- if Device:isKobo()
"reboot", -- if Device:isKobo()
"----------------------------", "----------------------------",
"exit", "exit_menu",
}, },
help = { help = {
"quickstart_guide", "quickstart_guide",
@ -104,6 +101,15 @@ local order = {
"----------------------------", "----------------------------",
"about", "about",
}, },
exit_menu = {
"restart_koreader",
"----------------------------",
"sleep", -- if Device:isKindle() or Device:isKobo()
"poweroff", -- if Device:isKobo()
"reboot", -- if Device:isKobo()
"----------------------------",
"exit",
}
} }
return order return order

@ -121,6 +121,7 @@ function MenuSorter:sort(item_table, order)
changed = true changed = true
local sub_menu_content = menu_table[sub_menu] local sub_menu_content = menu_table[sub_menu]
sub_menu_position.text = sub_menu_content.text sub_menu_position.text = sub_menu_content.text
sub_menu_position.hold_callback = sub_menu_content.hold_callback
sub_menu_position.sub_item_table = sub_menu_content sub_menu_position.sub_item_table = sub_menu_content
-- remove reference from top level output -- remove reference from top level output
menu_table[sub_menu] = nil menu_table[sub_menu] = nil

Loading…
Cancel
Save