mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
cervantes: add usb storage on devices w/updated 3rd party tools
This commit is contained in:
@@ -21,6 +21,14 @@ local function isConnected()
|
||||
return carrier
|
||||
end
|
||||
|
||||
local function isMassStorageSupported()
|
||||
-- we rely on 3rd party package for that. It should be installed as part of KOReader prerequisites,
|
||||
local safemode_version = io.open("/usr/share/safemode/version", "rb")
|
||||
if not safemode_version then return false end
|
||||
safemode_version:close()
|
||||
return true
|
||||
end
|
||||
|
||||
local Cervantes = Generic:new{
|
||||
model = "Cervantes",
|
||||
isCervantes = yes,
|
||||
@@ -33,6 +41,9 @@ local Cervantes = Generic:new{
|
||||
hasOTAUpdates = yes,
|
||||
hasKeys = yes,
|
||||
|
||||
-- do we support usb mass storage?
|
||||
canToggleMassStorage = function() return isMassStorageSupported() end,
|
||||
|
||||
-- all devices, except the original Cervantes Touch, have frontlight
|
||||
hasFrontlight = yes,
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ local Device = {
|
||||
hasColorScreen = no,
|
||||
hasBGRFrameBuffer = no,
|
||||
canToggleGSensor = no,
|
||||
canToggleMassStorage = no,
|
||||
|
||||
-- use these only as a last resort. We should abstract the functionality
|
||||
-- and have device dependent implementations in the corresponting
|
||||
|
||||
@@ -21,6 +21,22 @@ if Device:hasFrontlight() then
|
||||
}
|
||||
end
|
||||
|
||||
if Device:canToggleMassStorage() then
|
||||
local MassStorage = require("ui/elements/mass_storage")
|
||||
|
||||
-- mass storage settings
|
||||
common_settings.mass_storage_settings = {
|
||||
text = _("USB mass storage"),
|
||||
sub_item_table = MassStorage:getSettingsMenuTable()
|
||||
}
|
||||
|
||||
-- mass storage actions
|
||||
common_settings.mass_storage_actions = {
|
||||
text = _("Start USB storage"),
|
||||
callback = function() MassStorage:start() end,
|
||||
}
|
||||
end
|
||||
|
||||
if Device:setDateTime() then
|
||||
common_settings.time = {
|
||||
text = _("Time and date"),
|
||||
|
||||
@@ -39,6 +39,7 @@ local order = {
|
||||
"time",
|
||||
"battery",
|
||||
"gesture",
|
||||
"mass_storage_settings",
|
||||
},
|
||||
network = {
|
||||
"network_wifi",
|
||||
@@ -95,6 +96,7 @@ local order = {
|
||||
"open_last_document",
|
||||
"----------------------------",
|
||||
"system_statistics",
|
||||
"mass_storage_actions",
|
||||
"----------------------------",
|
||||
"ota_update", -- if Device:hasOTAUpdates()
|
||||
"version",
|
||||
|
||||
54
frontend/ui/elements/mass_storage.lua
Normal file
54
frontend/ui/elements/mass_storage.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
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
|
||||
|
||||
-- mass storage settings menu
|
||||
function MassStorage:getSettingsMenuTable()
|
||||
return {
|
||||
{
|
||||
text = _("Disable confirmation popup"),
|
||||
checked_func = function() return not self:requireConfirmation() end,
|
||||
callback = function()
|
||||
G_reader_settings:saveSetting("mass_storage_confirmation_disabled", self:requireConfirmation())
|
||||
end,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
-- mass storage actions
|
||||
function MassStorage:getActionsMenuTable()
|
||||
return {
|
||||
{
|
||||
text = _("Start USB storage"),
|
||||
callback = function()
|
||||
self:start()
|
||||
end,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
-- exit KOReader and start mass storage mode.
|
||||
function MassStorage:start()
|
||||
if self:requireConfirmation() then
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Share storage via USB?\n"),
|
||||
ok_text = _("Share"),
|
||||
ok_callback = function()
|
||||
UIManager:quit()
|
||||
UIManager._exit_code = 86
|
||||
end,
|
||||
})
|
||||
else
|
||||
UIManager:quit()
|
||||
UIManager._exit_code = 86
|
||||
end
|
||||
end
|
||||
|
||||
return MassStorage
|
||||
@@ -61,6 +61,7 @@ local order = {
|
||||
"time",
|
||||
"battery",
|
||||
"gesture",
|
||||
"mass_storage_settings",
|
||||
},
|
||||
network = {
|
||||
"network_wifi",
|
||||
@@ -119,6 +120,7 @@ local order = {
|
||||
"book_info",
|
||||
"----------------------------",
|
||||
"system_statistics",
|
||||
"mass_storage_actions",
|
||||
"----------------------------",
|
||||
"ota_update", -- if Device:hasOTAUpdates()
|
||||
"version",
|
||||
|
||||
@@ -82,10 +82,25 @@ if [ "${STANDALONE}" != "true" ]; then
|
||||
[ -x /etc/init.d/connman ] && /etc/init.d/connman stop
|
||||
fi
|
||||
|
||||
RETURN_VALUE=85
|
||||
while [ "${RETURN_VALUE}" -eq 85 ]; do
|
||||
# **magic** values to request shell stuff. It starts at 85,
|
||||
# any number lower than that will exit this script.
|
||||
RESTART_KOREADER=85
|
||||
ENTER_USBMS=86
|
||||
RETURN_VALUE="${RESTART_KOREADER}"
|
||||
|
||||
# Loop forever until KOReader requests a normal exit.
|
||||
while [ "${RETURN_VALUE}" -ge "${RESTART_KOREADER}" ]; do
|
||||
./reader.lua "${args}" >>crash.log 2>&1
|
||||
RETURN_VALUE=$?
|
||||
|
||||
# check if KOReader requested to enter in mass storage mode.
|
||||
if [ "${RETURN_VALUE}" -eq "${ENTER_USBMS}" ]; then
|
||||
# NOTE: at this point we're sure that the safemode tool
|
||||
# is recent enough to support the "--force" flag.
|
||||
|
||||
safemode storage --force 2>/dev/null
|
||||
# waiting forever for home button events.
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "${STANDALONE}" != "true" ]; then
|
||||
|
||||
Reference in New Issue
Block a user