From 19197648256775812128a30e9cf3c2092ee063c5 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Thu, 27 Aug 2020 01:06:41 +0200 Subject: [PATCH] Some more KoboUSBMS tweaks (#6566) * Enable i18n in KoboUSBMS * Rejig the "No confirmation" USBMS setting: In now *only* affects the USB plug in event. The menu entry will never show the popup (clicking on it should already be confirmation enough, that, yes, we really would like to do that, please ;)). Also, enable said plug in behavior on Cervantes, too ;). * Add an option to disable USBMS entirely * Bump base https://github.com/koreader/koreader-base/pull/1170 --- base | 2 +- .../elements/common_settings_menu_table.lua | 5 +-- frontend/ui/elements/mass_storage.lua | 34 ++++++++++++++----- frontend/ui/uimanager.lua | 6 +++- platform/kobo/koreader.sh | 9 ++++- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/base b/base index 42819cc85..eb88e0e03 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 42819cc85d9e3ec82c4ad56cc4fea33519114f06 +Subproject commit eb88e0e0339adcedab6d813b9c2fc4182239a99b diff --git a/frontend/ui/elements/common_settings_menu_table.lua b/frontend/ui/elements/common_settings_menu_table.lua index fca66bb47..656e3c96a 100644 --- a/frontend/ui/elements/common_settings_menu_table.lua +++ b/frontend/ui/elements/common_settings_menu_table.lua @@ -45,10 +45,7 @@ if Device:canToggleMassStorage() then } -- mass storage actions - common_settings.mass_storage_actions = { - text = _("Start USB storage"), - callback = function() MassStorage:start() end, - } + common_settings.mass_storage_actions = MassStorage:getActionsMenuTable() end -- This affects the topmenu, we want to be able to access it even if !Device:setDateTime() diff --git a/frontend/ui/elements/mass_storage.lua b/frontend/ui/elements/mass_storage.lua index 1cf35e01c..8a55d9a62 100644 --- a/frontend/ui/elements/mass_storage.lua +++ b/frontend/ui/elements/mass_storage.lua @@ -1,3 +1,4 @@ +local Device = require("device") local UIManager = require("ui/uimanager") local _ = require("gettext") @@ -8,35 +9,50 @@ function MassStorage:requireConfirmation() return not G_reader_settings:isTrue("mass_storage_confirmation_disabled") end +function MassStorage:isEnabled() + return not G_reader_settings:isTrue("mass_storage_disabled") +end + -- mass storage settings menu function MassStorage:getSettingsMenuTable() return { { text = _("Disable confirmation popup"), - help_text = _([[This will NOT affect what happens when you simply plug in the device!]]), + help_text = _([[This will ONLY affect what happens when you plug in the device!]]), checked_func = function() return not self:requireConfirmation() end, callback = function() G_reader_settings:saveSetting("mass_storage_confirmation_disabled", self:requireConfirmation()) end, }, + { + 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, + }, } end -- mass storage actions function MassStorage:getActionsMenuTable() return { - { - text = _("Start USB storage"), - callback = function() - self:start() - end, - }, + text = _("Start USB storage"), + enabled_func = function() return self:isEnabled() end, + callback = function() + self:start(true) + end, } end -- exit KOReader and start mass storage mode. -function MassStorage:start(always_ask) - if self:requireConfirmation() or always_ask then +function MassStorage:start(never_ask) + if not Device:canToggleMassStorage() or not self:isEnabled() then + return + end + + if not never_ask and self:requireConfirmation() then local ConfirmBox = require("ui/widget/confirmbox") UIManager:show(ConfirmBox:new{ text = _("Share storage via USB?"), diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 26c854564..4ae614c33 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -161,7 +161,7 @@ function UIManager:init() else -- Potentially start an USBMS session local MassStorage = require("ui/elements/mass_storage") - MassStorage:start(true) + MassStorage:start() end end self.event_handlers["NotCharging"] = function() @@ -315,6 +315,10 @@ function UIManager:init() self:_beforeCharging() if Device.screen_saver_mode then self:suspend() + else + -- Potentially start an USBMS session + local MassStorage = require("ui/elements/mass_storage") + MassStorage:start() end end self.event_handlers["USbPlugOut"] = function() diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index c9cceaff8..b80e20989 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -365,9 +365,16 @@ while [ ${RETURN_VALUE} -ne 0 ]; do mkdir -p "/tmp/usbms" ./tar xzf "./data/KoboUSBMS.tar.gz" -C "/tmp/usbms" + # Then siphon KOReader's language for i18n... + if grep -q '\["language"\]' 'settings.reader.lua' 2>/dev/null; then + usbms_lang="$(grep '\["language"\]' 'settings.reader.lua' | cut -d'"' -f4)" + else + usbms_lang="C" + fi + # Here we go! cd "/tmp/usbms" || continue - if ! ./usbms; then + if ! env LANGUAGE="${usbms_lang}" ./usbms; then # Hu, oh, something went wrong... Stay around for 90s (enough time to look at the syslog over Wi-Fi), and then shutdown. sleep 90 poweroff -f