2020-08-26 23:06:41 +00:00
|
|
|
local Device = require("device")
|
2021-05-17 21:59:32 +00:00
|
|
|
local Event = require("ui/event")
|
2019-02-15 00:18:30 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
local MassStorage = {}
|
|
|
|
|
|
|
|
-- if required a popup will ask before entering mass storage mode
|
|
|
|
function MassStorage:requireConfirmation()
|
|
|
|
return not G_reader_settings:isTrue("mass_storage_confirmation_disabled")
|
|
|
|
end
|
|
|
|
|
2020-08-26 23:06:41 +00:00
|
|
|
function MassStorage:isEnabled()
|
|
|
|
return not G_reader_settings:isTrue("mass_storage_disabled")
|
|
|
|
end
|
|
|
|
|
2019-02-15 00:18:30 +00:00
|
|
|
-- mass storage settings menu
|
|
|
|
function MassStorage:getSettingsMenuTable()
|
|
|
|
return {
|
|
|
|
{
|
|
|
|
text = _("Disable confirmation popup"),
|
2020-08-26 23:06:41 +00:00
|
|
|
help_text = _([[This will ONLY affect what happens when you plug in the device!]]),
|
2019-02-15 00:18:30 +00:00
|
|
|
checked_func = function() return not self:requireConfirmation() end,
|
|
|
|
callback = function()
|
|
|
|
G_reader_settings:saveSetting("mass_storage_confirmation_disabled", self:requireConfirmation())
|
|
|
|
end,
|
|
|
|
},
|
2020-08-26 23:06:41 +00:00
|
|
|
{
|
|
|
|
text = _("Disable mass storage functionality"),
|
|
|
|
help_text = _([[In case your device uses an unsupported setup where you know it won't work properly.]]),
|
|
|
|
checked_func = function() return not self:isEnabled() end,
|
|
|
|
callback = function()
|
|
|
|
G_reader_settings:saveSetting("mass_storage_disabled", self:isEnabled())
|
|
|
|
end,
|
|
|
|
},
|
2019-02-15 00:18:30 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- mass storage actions
|
|
|
|
function MassStorage:getActionsMenuTable()
|
|
|
|
return {
|
2020-08-26 23:06:41 +00:00
|
|
|
text = _("Start USB storage"),
|
|
|
|
enabled_func = function() return self:isEnabled() end,
|
|
|
|
callback = function()
|
|
|
|
self:start(true)
|
|
|
|
end,
|
2019-02-15 00:18:30 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- exit KOReader and start mass storage mode.
|
2020-08-26 23:06:41 +00:00
|
|
|
function MassStorage:start(never_ask)
|
|
|
|
if not Device:canToggleMassStorage() or not self:isEnabled() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if not never_ask and self:requireConfirmation() then
|
2019-02-15 00:18:30 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2020-08-25 00:00:59 +00:00
|
|
|
text = _("Share storage via USB?"),
|
2019-02-15 00:18:30 +00:00
|
|
|
ok_text = _("Share"),
|
|
|
|
ok_callback = function()
|
2020-09-25 13:52:08 +00:00
|
|
|
-- save settings before activating USBMS:
|
|
|
|
UIManager:flushSettings()
|
2019-02-15 00:18:30 +00:00
|
|
|
UIManager._exit_code = 86
|
2021-05-17 21:59:32 +00:00
|
|
|
UIManager:broadcastEvent(Event:new("Close"))
|
|
|
|
UIManager:quit()
|
2019-02-15 00:18:30 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
else
|
2020-09-25 13:52:08 +00:00
|
|
|
-- save settings before activating USBMS:
|
|
|
|
UIManager:flushSettings()
|
2019-02-15 00:18:30 +00:00
|
|
|
UIManager._exit_code = 86
|
2021-05-17 21:59:32 +00:00
|
|
|
UIManager:broadcastEvent(Event:new("Close"))
|
|
|
|
UIManager:quit()
|
2019-02-15 00:18:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return MassStorage
|