From bf03f40ef218797cc1288efaaac817ee479d1e3a Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Wed, 22 Nov 2023 18:59:07 +0100 Subject: [PATCH] Dispatcher: Allow toggling USBMS (#11123) It's right next to actual exit/restart actions, so it'll never ask for confirmation. --- frontend/device/devicelistener.lua | 8 ++++++++ frontend/dispatcher.lua | 2 ++ frontend/ui/elements/mass_storage.lua | 13 ++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/frontend/device/devicelistener.lua b/frontend/device/devicelistener.lua index d040a70f3..3fccf3057 100644 --- a/frontend/device/devicelistener.lua +++ b/frontend/device/devicelistener.lua @@ -328,6 +328,14 @@ function DeviceListener:onToggleKeyRepeat(toggle) Device:toggleKeyRepeat(G_reader_settings:nilOrFalse("input_no_key_repeat")) end +function DeviceListener:onRequestUSBMS() + local MassStorage = require("ui/elements/mass_storage") + -- It already takes care of the canToggleMassStorage cap check for us + -- NOTE: Never request confirmation, it's sorted right next to exit, restart & friends in Dispatcher, + -- and they don't either... + MassStorage:start(false) +end + function DeviceListener:onRestart() self.ui.menu:exitOrRestart(function() UIManager:restartKOReader() end) end diff --git a/frontend/dispatcher.lua b/frontend/dispatcher.lua index 1f39e767b..a4f0efc91 100644 --- a/frontend/dispatcher.lua +++ b/frontend/dispatcher.lua @@ -66,6 +66,7 @@ local settingsList = { -- Device exit_screensaver = {category="none", event="ExitScreensaver", title=_("Exit screensaver"), device=true}, + start_usbms = {category="none", event="RequestUSBMS", title=_("Start USB storage"), device=true, condition=Device:canToggleMassStorage()}, suspend = {category="none", event="RequestSuspend", title=_("Suspend"), device=true, condition=Device:canSuspend()}, restart = {category="none", event="Restart", title=_("Restart KOReader"), device=true, condition=Device:canRestart()}, reboot = {category="none", event="RequestReboot", title=_("Reboot the device"), device=true, condition=Device:canReboot()}, @@ -281,6 +282,7 @@ local dispatcher_menu_order = { -- Device "exit_screensaver", + "start_usbms", "suspend", "restart", "reboot", diff --git a/frontend/ui/elements/mass_storage.lua b/frontend/ui/elements/mass_storage.lua index 626fe9c14..dcd207ef5 100644 --- a/frontend/ui/elements/mass_storage.lua +++ b/frontend/ui/elements/mass_storage.lua @@ -43,18 +43,25 @@ function MassStorage:getActionsMenuTable() text = _("Start USB storage"), enabled_func = function() return self:isEnabled() end, callback = function() - self:start(true) + self:start(false) end, } end -- exit KOReader and start mass storage mode. -function MassStorage:start(never_ask) +function MassStorage:start(with_confirmation) if not Device:canToggleMassStorage() or not self:isEnabled() then return end - if not never_ask and self:requireConfirmation() then + local ask + if with_confirmation ~= nil then + ask = with_confirmation + else + ask = self:requireConfirmation() + end + + if ask then local ConfirmBox = require("ui/widget/confirmbox") self.usbms_widget = ConfirmBox:new{ text = _("Share storage via USB?"),