Skip to content

Commit

Permalink
Dispatcher: Allow toggling USBMS (#11123)
Browse files Browse the repository at this point in the history
It's right next to actual exit/restart actions, so it'll never ask for confirmation.
  • Loading branch information
NiLuJe committed Nov 22, 2023
1 parent bba48fc commit bf03f40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions frontend/device/devicelistener.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions frontend/dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
Expand Down Expand Up @@ -281,6 +282,7 @@ local dispatcher_menu_order = {

-- Device
"exit_screensaver",
"start_usbms",
"suspend",
"restart",
"reboot",
Expand Down
13 changes: 10 additions & 3 deletions frontend/ui/elements/mass_storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?"),
Expand Down

0 comments on commit bf03f40

Please sign in to comment.