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")
|
2022-10-27 20:09:39 +00:00
|
|
|
local logger = require("logger")
|
2019-02-15 00:18:30 +00:00
|
|
|
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()
|
2023-11-22 17:59:07 +00:00
|
|
|
self:start(false)
|
2020-08-26 23:06:41 +00:00
|
|
|
end,
|
2019-02-15 00:18:30 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- exit KOReader and start mass storage mode.
|
2023-11-22 17:59:07 +00:00
|
|
|
function MassStorage:start(with_confirmation)
|
2020-08-26 23:06:41 +00:00
|
|
|
if not Device:canToggleMassStorage() or not self:isEnabled() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-11-22 17:59:07 +00:00
|
|
|
local ask
|
|
|
|
if with_confirmation ~= nil then
|
|
|
|
ask = with_confirmation
|
|
|
|
else
|
|
|
|
ask = self:requireConfirmation()
|
|
|
|
end
|
|
|
|
|
|
|
|
if ask then
|
2019-02-15 00:18:30 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2021-08-24 19:03:40 +00:00
|
|
|
self.usbms_widget = 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()
|
2022-10-27 20:09:39 +00:00
|
|
|
logger.info("Exiting KOReader to enter USBMS mode...")
|
2021-05-17 21:59:32 +00:00
|
|
|
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)
|
2019-02-15 00:18:30 +00:00
|
|
|
end,
|
2021-08-24 19:03:40 +00:00
|
|
|
cancel_callback = function()
|
|
|
|
self:dismiss()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
UIManager:show(self.usbms_widget)
|
2019-02-15 00:18:30 +00:00
|
|
|
else
|
2020-09-25 13:52:08 +00:00
|
|
|
-- save settings before activating USBMS:
|
|
|
|
UIManager:flushSettings()
|
2022-10-27 20:09:39 +00:00
|
|
|
logger.info("Exiting KOReader to enter USBMS mode...")
|
2021-05-17 21:59:32 +00:00
|
|
|
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)
|
2019-02-15 00:18:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-24 19:03:40 +00:00
|
|
|
-- Dismiss the ConfirmBox
|
|
|
|
function MassStorage:dismiss()
|
|
|
|
if not self.usbms_widget then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
UIManager:close(self.usbms_widget)
|
|
|
|
self.usbms_widget = nil
|
|
|
|
end
|
|
|
|
|
2019-02-15 00:18:30 +00:00
|
|
|
return MassStorage
|