From 8e31bc8a68da659d803176a61d77b39f6b1666df Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 1 Nov 2022 23:41:14 +0100 Subject: [PATCH] ExternalKeyboard: Simplify the menu shenanigans checked_func implies keep_menu_open anyway --- frontend/ui/widget/touchmenu.lua | 2 +- plugins/externalkeyboard.koplugin/main.lua | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frontend/ui/widget/touchmenu.lua b/frontend/ui/widget/touchmenu.lua index 16b2f87a4..02d8ca2c6 100644 --- a/frontend/ui/widget/touchmenu.lua +++ b/frontend/ui/widget/touchmenu.lua @@ -871,7 +871,7 @@ function TouchMenu:onMenuSelect(item, tap_on_checkmark) if callback then -- Provide callback with us, so it can call our -- 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) callback(self) if refresh then diff --git a/plugins/externalkeyboard.koplugin/main.lua b/plugins/externalkeyboard.koplugin/main.lua index 23ed926cb..46e5f6b27 100644 --- a/plugins/externalkeyboard.koplugin/main.lua +++ b/plugins/externalkeyboard.koplugin/main.lua @@ -136,13 +136,11 @@ function ExternalKeyboard:addToMainMenu(menu_items) callback = function(touchmenu_instance) local role = self:getOTGRole() 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 - UIManager:nextTick(self.setOTGRole, self, new_role) + self:setOTGRole(new_role) end, }, { text = _("Always enable OTG mode"), - keep_menu_open = true, checked_func = function() return G_reader_settings:isTrue("external_keyboard_otg_mode_on_start") end, @@ -257,6 +255,13 @@ function ExternalKeyboard:_onEvdevInputRemove(evdev) ExternalKeyboard.original_device_values = nil 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: -- * 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.