ExternalKeyboard: Simplify the menu shenanigans

checked_func implies keep_menu_open anyway
reviewable/pr9739/r1
NiLuJe 2 years ago
parent 925fd647dc
commit 8e31bc8a68

@ -871,7 +871,7 @@ function TouchMenu:onMenuSelect(item, tap_on_checkmark)
if callback then if callback then
-- Provide callback with us, so it can call our -- Provide callback with us, so it can call our
-- closemenu() or updateItems() when it sees fit -- closemenu() or updateItems() when it sees fit
-- (if not providing checked or checked_fund, caller -- (if not providing checked or checked_func, caller
-- must set keep_menu_open=true if that is wished) -- must set keep_menu_open=true if that is wished)
callback(self) callback(self)
if refresh then if refresh then

@ -136,13 +136,11 @@ function ExternalKeyboard:addToMainMenu(menu_items)
callback = function(touchmenu_instance) callback = function(touchmenu_instance)
local role = self:getOTGRole() local role = self:getOTGRole()
local new_role = (role == USB_ROLE_DEVICE) and USB_ROLE_HOST or USB_ROLE_DEVICE local new_role = (role == USB_ROLE_DEVICE) and USB_ROLE_HOST or USB_ROLE_DEVICE
-- Let the menu close itself first, as the event cascade might reinit stuff and close it anyway self:setOTGRole(new_role)
UIManager:nextTick(self.setOTGRole, self, new_role)
end, end,
}, },
{ {
text = _("Always enable OTG mode"), text = _("Always enable OTG mode"),
keep_menu_open = true,
checked_func = function() checked_func = function()
return G_reader_settings:isTrue("external_keyboard_otg_mode_on_start") return G_reader_settings:isTrue("external_keyboard_otg_mode_on_start")
end, end,
@ -257,6 +255,13 @@ function ExternalKeyboard:_onEvdevInputRemove(evdev)
ExternalKeyboard.original_device_values = nil ExternalKeyboard.original_device_values = nil
end end
-- Only show this once
if ExternalKeyboard.connected_keyboards == 0 then
UIManager:show(InfoMessage:new{
text = _("Keyboard disconnected"),
timeout = 1,
})
end
-- There's a two-pronged approach here: -- There's a two-pronged approach here:
-- * Call a static class method to modify the class state for future instances of said class -- * Call a static class method to modify the class state for future instances of said class
-- * Broadcast an Event so that all currently displayed widgets update their own state. -- * Broadcast an Event so that all currently displayed widgets update their own state.

Loading…
Cancel
Save