diff --git a/frontend/ui/elements/common_settings_menu_table.lua b/frontend/ui/elements/common_settings_menu_table.lua index c4706050c..3a313cd0c 100644 --- a/frontend/ui/elements/common_settings_menu_table.lua +++ b/frontend/ui/elements/common_settings_menu_table.lua @@ -106,38 +106,6 @@ if Device:setDateTime() then } end -if Device:isCervantes() or Device:isKobo() or Device:isSDL() or Device:isSonyPRSTUX() then - common_settings.autosuspend = { - text = _("Autosuspend timeout"), - enabled_func = function() - -- NOTE: Pilfered from frontend/pluginloader.lua - local plugins_disabled = G_reader_settings:readSetting("plugins_disabled") or {} - return plugins_disabled["autosuspend"] ~= true - end, - callback = function() - local SpinWidget = require("ui/widget/spinwidget") - local curr_items = G_reader_settings:readSetting("auto_suspend_timeout_seconds") or 60*60 - local autosuspend_spin = SpinWidget:new { - width = Screen:getWidth() * 0.6, - value = curr_items / 60, - value_min = 5, - value_max = 240, - value_hold_step = 15, - ok_text = _("Set timeout"), - title_text = _("Timeout in minutes"), - callback = function(autosuspend_spin) - G_reader_settings:saveSetting("auto_suspend_timeout_seconds", autosuspend_spin.value * 60) - -- NOTE: Will only take effect after a restart, as we don't have a method to set this live... - UIManager:show(InfoMessage:new{ - text = _("This will take effect on next restart."), - }) - end - } - UIManager:show(autosuspend_spin) - end - } -end - if Device:isKobo() then common_settings.sleepcover = { text = _("Ignore sleepcover events"), diff --git a/plugins/autosuspend.koplugin/main.lua b/plugins/autosuspend.koplugin/main.lua index ca73fef1e..690fe510a 100644 --- a/plugins/autosuspend.koplugin/main.lua +++ b/plugins/autosuspend.koplugin/main.lua @@ -116,6 +116,49 @@ local AutoSuspendWidget = WidgetContainer:new{ name = "autosuspend", } +function AutoSuspendWidget:addToMainMenu(menu_items) + menu_items.autosuspend = { + text = _("Autosuspend timeout"), + -- This won't ever be registered if the plugin is disabled ;). + --[[ + enabled_func = function() + -- NOTE: Pilfered from frontend/pluginloader.lua + local plugins_disabled = G_reader_settings:readSetting("plugins_disabled") or {} + return plugins_disabled["autosuspend"] ~= true + end, + --]] + callback = function() + local InfoMessage = require("ui/widget/infomessage") + local Screen = Device.screen + local SpinWidget = require("ui/widget/spinwidget") + local curr_items = G_reader_settings:readSetting("auto_suspend_timeout_seconds") or 60*60 + local autosuspend_spin = SpinWidget:new { + width = Screen:getWidth() * 0.6, + value = curr_items / 60, + value_min = 5, + value_max = 240, + value_hold_step = 15, + ok_text = _("Set timeout"), + title_text = _("Timeout in minutes"), + callback = function(autosuspend_spin) + G_reader_settings:saveSetting("auto_suspend_timeout_seconds", autosuspend_spin.value * 60) + -- NOTE: Will only take effect after a restart, as we don't have a method to set this live... + UIManager:show(InfoMessage:new{ + text = _("This will take effect on next restart."), + }) + end + } + UIManager:show(autosuspend_spin) + end, + } +end + +function AutoSuspendWidget:init() + -- self.ui is nil in the testsuite + if not self.ui or not self.ui.menu then return end + self.ui.menu:registerToMainMenu(self) +end + function AutoSuspendWidget:onInputEvent() AutoSuspend:onInputEvent() end