mirror of
https://github.com/koreader/koreader.git
synced 2025-12-18 12:02:09 +01:00
ReaderMenu/FileManagerMenu: deduplicate Exit menu code (#8459)
This commit is contained in:
@@ -763,30 +763,9 @@ Tap a book in the search results to open it.]]),
|
|||||||
for id, common_setting in pairs(dofile("frontend/ui/elements/common_info_menu_table.lua")) do
|
for id, common_setting in pairs(dofile("frontend/ui/elements/common_info_menu_table.lua")) do
|
||||||
self.menu_items[id] = common_setting
|
self.menu_items[id] = common_setting
|
||||||
end
|
end
|
||||||
self.menu_items.exit_menu = {
|
-- insert common exit for filemanager
|
||||||
text = _("Exit"),
|
for id, common_setting in pairs(dofile("frontend/ui/elements/common_exit_menu_table.lua")) do
|
||||||
hold_callback = function()
|
self.menu_items[id] = common_setting
|
||||||
self:exitOrRestart()
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
self.menu_items.exit = {
|
|
||||||
text = _("Exit"),
|
|
||||||
callback = function()
|
|
||||||
self:exitOrRestart()
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
self.menu_items.restart_koreader = {
|
|
||||||
text = _("Restart KOReader"),
|
|
||||||
callback = function()
|
|
||||||
self:exitOrRestart(function()
|
|
||||||
UIManager:restartKOReader()
|
|
||||||
end)
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
if not Device:canRestart() then
|
|
||||||
self.menu_items.exit_menu = self.menu_items.exit
|
|
||||||
self.menu_items.exit = nil
|
|
||||||
self.menu_items.restart_koreader = nil
|
|
||||||
end
|
end
|
||||||
if not Device:isTouchDevice() then
|
if not Device:isTouchDevice() then
|
||||||
-- add a shortcut on non touch-device
|
-- add a shortcut on non touch-device
|
||||||
|
|||||||
@@ -251,29 +251,9 @@ function ReaderMenu:setUpdateItemTable()
|
|||||||
for id, common_setting in pairs(dofile("frontend/ui/elements/common_info_menu_table.lua")) do
|
for id, common_setting in pairs(dofile("frontend/ui/elements/common_info_menu_table.lua")) do
|
||||||
self.menu_items[id] = common_setting
|
self.menu_items[id] = common_setting
|
||||||
end
|
end
|
||||||
|
-- insert common exit for reader
|
||||||
self.menu_items.exit_menu = {
|
for id, common_setting in pairs(dofile("frontend/ui/elements/common_exit_menu_table.lua")) do
|
||||||
text = _("Exit"),
|
self.menu_items[id] = common_setting
|
||||||
hold_callback = function()
|
|
||||||
self:exitOrRestart()
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
self.menu_items.exit = {
|
|
||||||
text = _("Exit"),
|
|
||||||
callback = function()
|
|
||||||
self:exitOrRestart()
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
self.menu_items.restart_koreader = {
|
|
||||||
text = _("Restart KOReader"),
|
|
||||||
callback = function()
|
|
||||||
self:exitOrRestart(function() UIManager:restartKOReader() end)
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
if not Device:canRestart() then
|
|
||||||
self.menu_items.exit_menu = self.menu_items.exit
|
|
||||||
self.menu_items.exit = nil
|
|
||||||
self.menu_items.restart_koreader = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.menu_items.open_previous_document = {
|
self.menu_items.open_previous_document = {
|
||||||
|
|||||||
56
frontend/ui/elements/common_exit_menu_table.lua
Normal file
56
frontend/ui/elements/common_exit_menu_table.lua
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
local Device = require("device")
|
||||||
|
local Event = require("ui/event")
|
||||||
|
local UIManager = require("ui/uimanager")
|
||||||
|
local _ = require("gettext")
|
||||||
|
|
||||||
|
local exit_settings = {}
|
||||||
|
|
||||||
|
exit_settings.exit_menu = {
|
||||||
|
text = _("Exit"),
|
||||||
|
-- submenu entries will be appended by xyz_menu_order_lua
|
||||||
|
}
|
||||||
|
exit_settings.exit = {
|
||||||
|
text = _("Exit"),
|
||||||
|
callback = function()
|
||||||
|
UIManager:broadcastEvent(Event:new("Exit"))
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
exit_settings.restart_koreader = {
|
||||||
|
text = _("Restart KOReader"),
|
||||||
|
callback = function()
|
||||||
|
UIManager:broadcastEvent(Event:new("Restart"))
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
if not Device:canRestart() then
|
||||||
|
exit_settings.exit_menu = exit_settings.exit
|
||||||
|
exit_settings.exit = nil
|
||||||
|
exit_settings.restart_koreader = nil
|
||||||
|
end
|
||||||
|
if Device:canSuspend() then
|
||||||
|
exit_settings.sleep = {
|
||||||
|
text = _("Sleep"),
|
||||||
|
callback = function()
|
||||||
|
UIManager:suspend()
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if Device:canReboot() then
|
||||||
|
exit_settings.reboot = {
|
||||||
|
text = _("Reboot the device"),
|
||||||
|
keep_menu_open = true,
|
||||||
|
callback = function()
|
||||||
|
UIManager:broadcastEvent(Event:new("Reboot"))
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if Device:canPowerOff() then
|
||||||
|
exit_settings.poweroff = {
|
||||||
|
text = _("Power off"),
|
||||||
|
keep_menu_open = true,
|
||||||
|
callback = function()
|
||||||
|
UIManager:broadcastEvent(Event:new("PowerOff"))
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return exit_settings
|
||||||
@@ -77,31 +77,4 @@ common_info.report_bug = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
if Device:canSuspend() then
|
|
||||||
common_info.sleep = {
|
|
||||||
text = _("Sleep"),
|
|
||||||
callback = function()
|
|
||||||
UIManager:suspend()
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
if Device:canReboot() then
|
|
||||||
common_info.reboot = {
|
|
||||||
text = _("Reboot the device"),
|
|
||||||
keep_menu_open = true,
|
|
||||||
callback = function()
|
|
||||||
UIManager:broadcastEvent(Event:new("Reboot"))
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
if Device:canPowerOff() then
|
|
||||||
common_info.poweroff = {
|
|
||||||
text = _("Power off"),
|
|
||||||
keep_menu_open = true,
|
|
||||||
callback = function()
|
|
||||||
UIManager:broadcastEvent(Event:new("PowerOff"))
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
return common_info
|
return common_info
|
||||||
|
|||||||
Reference in New Issue
Block a user