2
0
mirror of https://github.com/koreader/koreader synced 2024-11-13 19:11:25 +00:00
koreader/frontend/ui/elements/mass_storage.lua

102 lines
3.1 KiB
Lua
Raw Permalink Normal View History

local Device = require("device")
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
local logger = require("logger")
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
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 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"),
enabled_func = function() return self:isEnabled() end,
callback = function()
self:start(false)
end,
}
end
-- exit KOReader and start mass storage mode.
function MassStorage:start(with_confirmation)
if not Device:canToggleMassStorage() or not self:isEnabled() then
return
end
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?"),
ok_text = _("Share"),
ok_callback = function()
-- save settings before activating USBMS:
UIManager:flushSettings()
logger.info("Exiting KOReader to enter USBMS mode...")
UIManager:broadcastEvent(Event:new("Close"))
Assorted bag'o tweaks & fixes (#9569) * UIManager: Support more specialized update modes for corner-cases: * A2, which we'll use for the VirtualKeyboards keys (they'd... inadvertently switched to UI with the highlight refactor). * NO_MERGE variants of ui & partial (for sunxi). Use `[ui]` in ReaderHighlight's popup, because of a Sage kernel bug that could otherwise make it translucent, sometimes completely so (*sigh*). * UIManager: Assorted code cleanups & simplifications. * Logger & dbg: Unify logging style, and code cleanups. * SDL: Unbreak suspend/resume outside of the emulator (fix #9567). * NetworkMgr: Cache the network status, and allow it to be queried. (Used by AutoSuspend to avoid repeatedly poking the system when computing the standby schedule delay). * OneTimeMigration: Don't forget about `NETWORK_PROXY` & `STARDICT_DATA_DIR` when migrating `defaults.persistent.lua` (fix #9573) * WakeupMgr: Workaround an apparent limitation of the RTC found on i.MX5 Kobo devices, where setting a wakealarm further than UINT16_MAX seconds in the future would apparently overflow and wraparound... (fix #8039, many thanks to @yfede for the extensive deep-dive and for actually accurately pinpointing the issue!). * Kobo: Handle standby transitions at full CPU clock speeds, in order to limit the latency hit. * UIManager: Properly quit on reboot & exit. This ensures our exit code is preserved, as we exit on our own terms (instead of being killed by the init system). This is important on platforms where exit codes are semantically meaningful (e.g., Kobo). * UIManager: Speaking of reboot & exit, make sure the Screensaver shows in all circumstances (e.g., autoshutdown, re: #9542)), and that there aren't any extraneous refreshes triggered. (Additionally, fix a minor regression since #9448 about tracking this very transient state on Kobo & Cervantes). * Kindle: ID the upcoming Scribe. * Bump base (https://github.com/koreader/koreader-base/pull/1524)
2022-10-02 01:01:49 +00:00
UIManager:quit(86)
end,
cancel_callback = function()
self:dismiss()
end,
}
UIManager:show(self.usbms_widget)
else
-- save settings before activating USBMS:
UIManager:flushSettings()
logger.info("Exiting KOReader to enter USBMS mode...")
UIManager:broadcastEvent(Event:new("Close"))
Assorted bag'o tweaks & fixes (#9569) * UIManager: Support more specialized update modes for corner-cases: * A2, which we'll use for the VirtualKeyboards keys (they'd... inadvertently switched to UI with the highlight refactor). * NO_MERGE variants of ui & partial (for sunxi). Use `[ui]` in ReaderHighlight's popup, because of a Sage kernel bug that could otherwise make it translucent, sometimes completely so (*sigh*). * UIManager: Assorted code cleanups & simplifications. * Logger & dbg: Unify logging style, and code cleanups. * SDL: Unbreak suspend/resume outside of the emulator (fix #9567). * NetworkMgr: Cache the network status, and allow it to be queried. (Used by AutoSuspend to avoid repeatedly poking the system when computing the standby schedule delay). * OneTimeMigration: Don't forget about `NETWORK_PROXY` & `STARDICT_DATA_DIR` when migrating `defaults.persistent.lua` (fix #9573) * WakeupMgr: Workaround an apparent limitation of the RTC found on i.MX5 Kobo devices, where setting a wakealarm further than UINT16_MAX seconds in the future would apparently overflow and wraparound... (fix #8039, many thanks to @yfede for the extensive deep-dive and for actually accurately pinpointing the issue!). * Kobo: Handle standby transitions at full CPU clock speeds, in order to limit the latency hit. * UIManager: Properly quit on reboot & exit. This ensures our exit code is preserved, as we exit on our own terms (instead of being killed by the init system). This is important on platforms where exit codes are semantically meaningful (e.g., Kobo). * UIManager: Speaking of reboot & exit, make sure the Screensaver shows in all circumstances (e.g., autoshutdown, re: #9542)), and that there aren't any extraneous refreshes triggered. (Additionally, fix a minor regression since #9448 about tracking this very transient state on Kobo & Cervantes). * Kindle: ID the upcoming Scribe. * Bump base (https://github.com/koreader/koreader-base/pull/1524)
2022-10-02 01:01:49 +00:00
UIManager:quit(86)
end
end
-- Dismiss the ConfirmBox
function MassStorage:dismiss()
if not self.usbms_widget then
return
end
UIManager:close(self.usbms_widget)
self.usbms_widget = nil
end
return MassStorage