mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #2245 from koreader/houqp-master
always suspend device when closing sleep cover
This commit is contained in:
@@ -6,6 +6,4 @@ source "${CI_DIR}/common.sh"
|
||||
travis_retry make fetchthirdparty
|
||||
make all
|
||||
make testfront
|
||||
set +o pipefail
|
||||
luajit $(which luacheck) --no-color -q frontend | tee ./luacheck.out
|
||||
test $(grep Total ./luacheck.out | awk '{print $2}') -le 19
|
||||
luajit $(which luacheck) --no-color -q frontend
|
||||
|
||||
@@ -78,14 +78,14 @@ read_globals = {
|
||||
"DDICT_FONT_SIZE",
|
||||
"FRONTLIGHT_SENSITIVITY_DECREASE",
|
||||
"DALPHA_SORT_CASE_INSENSITIVE",
|
||||
"SEARCH_LIBRARY_PATH",
|
||||
"SEARCH_LIBRARY_PATH2",
|
||||
"SEARCH_CASESENSITIVE",
|
||||
"SEARCH_AUTHORS",
|
||||
"SEARCH_TITLE",
|
||||
"SEARCH_TAGS",
|
||||
"SEARCH_SERIES",
|
||||
"SEARCH_PATH",
|
||||
"SEARCH_LIBRARY_PATH",
|
||||
"SEARCH_LIBRARY_PATH2",
|
||||
"KOBO_LIGHT_ON_START",
|
||||
"NETWORK_PROXY",
|
||||
"DUSE_TURBO_LIB",
|
||||
|
||||
2
base
2
base
Submodule base updated: 3e9b63f5ca...9f0a70e9ea
@@ -136,7 +136,7 @@ DMINIBAR_HEIGHT = 7 -- Should be smaller than DMINIBAR_CONTAINER_HEI
|
||||
DMINIBAR_CONTAINER_HEIGHT = 14 -- Larger means more padding at the bottom, at the risk of eating into the last line
|
||||
DMINIBAR_FONT_SIZE = 14
|
||||
|
||||
-- change this to any numerical value if you want to antomatically save settings when turning pages
|
||||
-- change this to any numerical value if you want to automatically save settings when turning pages
|
||||
DAUTO_SAVE_PAGING_COUNT = nil
|
||||
|
||||
-- dictionary font size
|
||||
|
||||
@@ -36,8 +36,8 @@ function FileManagerMenu:init()
|
||||
home = {
|
||||
icon = "resources/icons/appbar.home.png",
|
||||
callback = function()
|
||||
if settings_changed then
|
||||
settings_changed = false
|
||||
if SetDefaults.settings_changed then
|
||||
SetDefaults.settings_changed = false
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("You have unsaved default settings. Save them now?"),
|
||||
ok_callback = function()
|
||||
|
||||
@@ -12,6 +12,7 @@ local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
local T = require("ffi/util").template
|
||||
local _ = require("gettext")
|
||||
local SetDefaults = require("apps/filemanager/filemanagersetdefaults")
|
||||
|
||||
local calibre = "metadata.calibre"
|
||||
local koreaderfile = "temp/metadata.koreader"
|
||||
@@ -75,11 +76,11 @@ function Search:getCalibre()
|
||||
if not self.metafile_1 then
|
||||
self.error = _("SEARCH_LIBRARY_PATH should be defined in DEFAULTS.LUA.")
|
||||
else
|
||||
settings_changed = true
|
||||
SetDefaults.settings_changed = true
|
||||
end
|
||||
else
|
||||
if string.sub(SEARCH_LIBRARY_PATH,string.len(SEARCH_LIBRARY_PATH)) ~= "/" then
|
||||
SEARCH_LIBRARY_PATH = SEARCH_LIBRARY_PATH .. "/"
|
||||
SEARCH_LIBRARY_PATH = SEARCH_LIBRARY_PATH .. "/" -- luacheck: ignore
|
||||
end
|
||||
if io.open(SEARCH_LIBRARY_PATH .. calibre,"r") == nil then
|
||||
if io.open(SEARCH_LIBRARY_PATH .. "." .. calibre,"r") == nil then
|
||||
@@ -98,7 +99,7 @@ function Search:getCalibre()
|
||||
elseif self.metafile_1 == nil then
|
||||
self.metafile_1 = findcalibre("/mnt")
|
||||
if self.metafile_1 then
|
||||
settings_changed = true
|
||||
SetDefaults.settings_changed = true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -106,7 +107,7 @@ function Search:getCalibre()
|
||||
local dummy
|
||||
|
||||
if string.sub(SEARCH_LIBRARY_PATH2,string.len(SEARCH_LIBRARY_PATH2)) ~= "/" then
|
||||
SEARCH_LIBRARY_PATH2 = SEARCH_LIBRARY_PATH2 .. "/"
|
||||
SEARCH_LIBRARY_PATH2 = SEARCH_LIBRARY_PATH2 .. "/" -- luacheck: ignore
|
||||
end
|
||||
if io.open(SEARCH_LIBRARY_PATH2 .. calibre,"r") == nil then
|
||||
if io.open(SEARCH_LIBRARY_PATH2 .. "." .. calibre,"r") ~= nil then
|
||||
@@ -152,7 +153,7 @@ function Search:ShowSearch()
|
||||
enabled = true,
|
||||
callback = function()
|
||||
self.search_value = self.search_dialog:getInputText()
|
||||
if not settings_changed and self.search_value == dummy and self.lastsearch == "series" then
|
||||
if not SetDefaults.settings_changed and self.search_value == dummy and self.lastsearch == "series" then
|
||||
self.use_previous_search_results = true
|
||||
else
|
||||
self.use_previous_search_results = false
|
||||
@@ -166,7 +167,7 @@ function Search:ShowSearch()
|
||||
enabled = true,
|
||||
callback = function()
|
||||
self.search_value = self.search_dialog:getInputText()
|
||||
if not settings_changed and self.search_value == dummy and self.lastsearch == "tags" then
|
||||
if not SetDefaults.settings_changed and self.search_value == dummy and self.lastsearch == "tags" then
|
||||
self.use_previous_search_results = true
|
||||
else
|
||||
self.use_previous_search_results = false
|
||||
@@ -190,7 +191,7 @@ function Search:ShowSearch()
|
||||
enabled = true,
|
||||
callback = function()
|
||||
self.search_value = self.search_dialog:getInputText()
|
||||
if not settings_changed and self.search_value == dummy and self.lastsearch == "find" then
|
||||
if not SetDefaults.settings_changed and self.search_value == dummy and self.lastsearch == "find" then
|
||||
self.use_previous_search_results = true
|
||||
else
|
||||
self.use_previous_search_results = false
|
||||
@@ -235,7 +236,6 @@ function Search:find(option)
|
||||
local line
|
||||
local i = 1
|
||||
local upsearch
|
||||
local dummy
|
||||
local firstrun
|
||||
|
||||
-- removes leading and closing characters and converts hex-unicodes
|
||||
@@ -269,10 +269,10 @@ function Search:find(option)
|
||||
if s == self.authors then
|
||||
self.data[i][self.authors2] = self.data[i][self.authors2] .. " & " .. ReplaceHexChars(line,8,3)
|
||||
elseif s == self.tags then
|
||||
local dummy = ReplaceHexChars(line,8,3)
|
||||
self.data[i][self.tags2] = self.data[i][self.tags2] .. " & " .. dummy
|
||||
self.data[i][self.tags3] = self.data[i][self.tags3] .. "\t" .. dummy
|
||||
self.browse_tags[dummy] = (self.browse_tags[dummy] or 0) + 1
|
||||
local tags_line = ReplaceHexChars(line,8,3)
|
||||
self.data[i][self.tags2] = self.data[i][self.tags2] .. " & " .. tags_line
|
||||
self.data[i][self.tags3] = self.data[i][self.tags3] .. "\t" .. tags_line
|
||||
self.browse_tags[tags_line] = (self.browse_tags[tags_line] or 0) + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -318,16 +318,24 @@ function Search:find(option)
|
||||
line = g:read()
|
||||
end
|
||||
|
||||
local dummy = ""
|
||||
if option == "find" and SEARCH_AUTHORS then dummy = dummy .. self.data[i][self.authors] .. "\n" end
|
||||
if option == "find" and SEARCH_TITLE then dummy = dummy .. self.data[i][self.title] .. "\n" end
|
||||
if option == "find" and SEARCH_PATH then dummy = dummy .. self.data[i][self.path] .. "\n" end
|
||||
local search_content = ""
|
||||
if option == "find" and SEARCH_AUTHORS then
|
||||
search_content = search_content .. self.data[i][self.authors] .. "\n"
|
||||
end
|
||||
if option == "find" and SEARCH_TITLE then
|
||||
search_content = search_content .. self.data[i][self.title] .. "\n"
|
||||
end
|
||||
if option == "find" and SEARCH_PATH then
|
||||
search_content = search_content .. self.data[i][self.path] .. "\n"
|
||||
end
|
||||
if (option == "series" or SEARCH_SERIES) and self.data[i][self.series] ~= "-" then
|
||||
dummy = dummy .. self.data[i][self.series] .. "\n"
|
||||
search_content = search_content .. self.data[i][self.series] .. "\n"
|
||||
self.browse_series[self.data[i][self.series]] = (self.browse_series[self.data[i][self.series]] or 0) + 1
|
||||
end
|
||||
if option == "tags" or SEARCH_TAGS then dummy = dummy .. self.data[i][self.tags] .. "\n" end
|
||||
if not SEARCH_CASESENSITIVE then dummy = string.upper(dummy) end
|
||||
if option == "tags" or SEARCH_TAGS then
|
||||
search_content = search_content .. self.data[i][self.tags] .. "\n"
|
||||
end
|
||||
if not SEARCH_CASESENSITIVE then search_content = string.upper(search_content) end
|
||||
|
||||
for j in string.gmatch(self.data[i][self.tags3],"\t[^\t]+") do
|
||||
if j~="\t" then
|
||||
@@ -336,7 +344,7 @@ function Search:find(option)
|
||||
end
|
||||
if DocumentRegistry:getProvider(self.data[i][self.path]) then
|
||||
if upsearch ~= "" then
|
||||
if string.find(dummy,upsearch,nil,true) then
|
||||
if string.find(search_content,upsearch,nil,true) then
|
||||
i = i + 1
|
||||
end
|
||||
else
|
||||
@@ -372,23 +380,23 @@ function Search:find(option)
|
||||
if line == " }, " or line == " }" then
|
||||
-- new calibre data set
|
||||
|
||||
dummy = ""
|
||||
if option == "find" and SEARCH_AUTHORS then dummy = dummy .. self.data[i][self.authors] .. "\n" end
|
||||
if option == "find" and SEARCH_TITLE then dummy = dummy .. self.data[i][self.title] .. "\n" end
|
||||
if option == "find" and SEARCH_PATH then dummy = dummy .. self.data[i][self.path] .. "\n" end
|
||||
local search_content = ""
|
||||
if option == "find" and SEARCH_AUTHORS then search_content = search_content .. self.data[i][self.authors] .. "\n" end
|
||||
if option == "find" and SEARCH_TITLE then search_content = search_content .. self.data[i][self.title] .. "\n" end
|
||||
if option == "find" and SEARCH_PATH then search_content = search_content .. self.data[i][self.path] .. "\n" end
|
||||
if (option == "series" or SEARCH_SERIES) and self.data[i][self.series] ~= "-" then
|
||||
dummy = dummy .. self.data[i][self.series] .. "\n"
|
||||
search_content = search_content .. self.data[i][self.series] .. "\n"
|
||||
self.browse_series[self.data[i][self.series]] = (self.browse_series[self.data[i][self.series]] or 0) + 1
|
||||
end
|
||||
if option == "tags" or SEARCH_TAGS then dummy = dummy .. self.data[i][self.tags] .. "\n" end
|
||||
if not SEARCH_CASESENSITIVE then dummy = string.upper(dummy) end
|
||||
if option == "tags" or SEARCH_TAGS then search_content = search_content .. self.data[i][self.tags] .. "\n" end
|
||||
if not SEARCH_CASESENSITIVE then search_content = string.upper(search_content) end
|
||||
|
||||
for j = 1,9 do
|
||||
g:write(self.data[i][j] .. "\n")
|
||||
end
|
||||
|
||||
if upsearch ~= "" then
|
||||
if string.find(dummy,upsearch,nil,true) then
|
||||
if string.find(search_content,upsearch,nil,true) then
|
||||
i = i + 1
|
||||
end
|
||||
else
|
||||
@@ -464,8 +472,7 @@ function Search:find(option)
|
||||
self:browse(option,1)
|
||||
end
|
||||
else
|
||||
dummy = _("No match for") .. " " .. self.search_value
|
||||
UIManager:show(InfoMessage:new{text = dummy})
|
||||
UIManager:show(InfoMessage:new{text = T(_("No match for %1."), self.search_value)})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -616,14 +623,14 @@ function Search:browse(option, run, chosen)
|
||||
local i = 1
|
||||
while i <= self.count do
|
||||
if (option == "tags" and self.data[i][self.tags3]:find("\t" .. chosen .. "\t",nil,true)) or (option == "series" and chosen == self.data[i][self.series]) then
|
||||
local dummy = _("Title: ") .. (self.data[i][self.title] or "-") .. "\n \n" ..
|
||||
local entry = _("Title: ") .. (self.data[i][self.title] or "-") .. "\n \n" ..
|
||||
_("Author(s):") .. " " .. (self.data[i][self.authors2] or "-") .. "\n \n" ..
|
||||
_("Tags:") .. " " .. (self.data[i][self.tags2] or "-") .. "\n \n" ..
|
||||
_("Series:") .. " " .. (self.data[i][self.series] or "-")
|
||||
if self.data[i][self.series] ~= "-" then
|
||||
dummy = dummy .. " (" .. tostring(self.data[i][self.series_index]):gsub(".0$","") .. ")"
|
||||
entry = entry .. " (" .. tostring(self.data[i][self.series_index]):gsub(".0$","") .. ")"
|
||||
end
|
||||
dummy = dummy .. "\n \n" .. _("Path: ")
|
||||
entry = entry .. "\n \n" .. _("Path: ")
|
||||
local book = self.data[i][self.path]
|
||||
local text
|
||||
if option == "series" then
|
||||
@@ -637,7 +644,7 @@ function Search:browse(option, run, chosen)
|
||||
end
|
||||
table.insert(self.results, {
|
||||
text = text,
|
||||
info = dummy,
|
||||
info = entry,
|
||||
notchecked = true,
|
||||
path = self.data[i][self.path],
|
||||
callback = function()
|
||||
|
||||
@@ -15,7 +15,7 @@ local dump = require("dump")
|
||||
|
||||
|
||||
local defaults_path = DataStorage:getDataDir() .. "/defaults.lua"
|
||||
local persistent_filename = DataStorage:getDataDir() .. "/defaults.persistent.lua"
|
||||
local persistent_defaults_path = DataStorage:getDataDir() .. "/defaults.persistent.lua"
|
||||
|
||||
|
||||
local SetDefaults = InputContainer:new{
|
||||
@@ -24,7 +24,8 @@ local SetDefaults = InputContainer:new{
|
||||
results = {},
|
||||
defaults_menu = {},
|
||||
initialized = false,
|
||||
changed = {}
|
||||
changed = {},
|
||||
settings_changed = false,
|
||||
}
|
||||
|
||||
function SetDefaults:ConfirmEdit()
|
||||
@@ -50,6 +51,14 @@ function SetDefaults:init()
|
||||
setfenv(load_defaults, defaults)
|
||||
load_defaults()
|
||||
|
||||
local file = io.open(persistent_defaults_path, "r")
|
||||
if file ~= nil then
|
||||
file:close()
|
||||
load_defaults = loadfile(persistent_defaults_path)
|
||||
setfenv(load_defaults, defaults)
|
||||
load_defaults()
|
||||
end
|
||||
|
||||
local i = 1
|
||||
for n, v in util.orderedPairs(defaults) do
|
||||
self.defaults_name[i] = n
|
||||
@@ -110,7 +119,7 @@ function SetDefaults:init()
|
||||
callback = function()
|
||||
self.defaults_value[i] = true
|
||||
_G[setting_name] = true
|
||||
settings_changed = true
|
||||
self.settings_changed = true
|
||||
self.changed[i] = true
|
||||
self.results[i].text = self:build_setting(i)
|
||||
self:close()
|
||||
@@ -124,7 +133,7 @@ function SetDefaults:init()
|
||||
callback = function()
|
||||
self.defaults_value[i] = false
|
||||
_G[setting_name] = false
|
||||
settings_changed = true
|
||||
self.settings_changed = true
|
||||
self.changed[i] = true
|
||||
self.results[i].text = self:build_setting(i)
|
||||
self.defaults_menu:swithItemTable("Defaults", self.results, i)
|
||||
@@ -172,7 +181,7 @@ function SetDefaults:init()
|
||||
_G[setting_name] = new_table
|
||||
|
||||
self.defaults_value[i] = _G[setting_name]
|
||||
settings_changed = true
|
||||
self.settings_changed = true
|
||||
self.changed[i] = true
|
||||
|
||||
self.results[i].text = self:build_setting(i)
|
||||
@@ -209,18 +218,11 @@ function SetDefaults:init()
|
||||
is_enter_default = true,
|
||||
enabled = true,
|
||||
callback = function()
|
||||
local new_value = self.set_dialog:getInputText()
|
||||
if setting_type == "boolean" then
|
||||
if new_value == "true" then
|
||||
new_value = true
|
||||
else
|
||||
new_value = false
|
||||
end
|
||||
end
|
||||
local new_value = self.set_dialog:getInputValue()
|
||||
if _G[setting_name] ~= new_value then
|
||||
_G[setting_name] = new_value
|
||||
self.defaults_value[i] = new_value
|
||||
settings_changed = true
|
||||
self.settings_changed = true
|
||||
self.changed[i] = true
|
||||
self.results[i].text = self:build_setting(i)
|
||||
end
|
||||
@@ -278,10 +280,10 @@ end
|
||||
function SetDefaults:saveSettings()
|
||||
self.results = {}
|
||||
local persisted_defaults = {}
|
||||
local file = io.open(persistent_filename, "r")
|
||||
local file = io.open(persistent_defaults_path, "r")
|
||||
if file ~= nil then
|
||||
file:close()
|
||||
local load_defaults = loadfile(persistent_filename)
|
||||
local load_defaults = loadfile(persistent_defaults_path)
|
||||
setfenv(load_defaults, persisted_defaults)
|
||||
load_defaults()
|
||||
end
|
||||
@@ -321,7 +323,7 @@ function SetDefaults:saveSettings()
|
||||
end
|
||||
end
|
||||
|
||||
file = io.open(persistent_filename, "w")
|
||||
file = io.open(persistent_defaults_path, "w")
|
||||
if file then
|
||||
file:write("-- For configuration changes that persists between updates\n")
|
||||
for k, v in pairs(persisted_defaults) do
|
||||
@@ -337,7 +339,7 @@ function SetDefaults:saveSettings()
|
||||
text = _("Default settings saved."),
|
||||
})
|
||||
end
|
||||
settings_changed = false
|
||||
self.settings_changed = false
|
||||
end
|
||||
|
||||
return SetDefaults
|
||||
|
||||
@@ -707,15 +707,13 @@ function ReaderPaging:onGotoPageRel(diff)
|
||||
local new_va = self.visible_area:copy()
|
||||
local x_pan_off, y_pan_off = 0, 0
|
||||
|
||||
if self.zoom_mode == "free" then
|
||||
-- do nothing in free zoom mode
|
||||
elseif self.zoom_mode:find("width") then
|
||||
if self.zoom_mode:find("width") then
|
||||
y_pan_off = self.visible_area.h * diff
|
||||
elseif self.zoom_mode:find("height") then
|
||||
-- negative x panning if writing direction is right to left
|
||||
local direction = self.ui.document.configurable.writing_direction
|
||||
x_pan_off = self.visible_area.w * diff * (direction == 1 and -1 or 1)
|
||||
else
|
||||
elseif self.zoom_mode ~= "free" then -- do nothing in "free" zoom mode
|
||||
-- must be fit content or page zoom mode
|
||||
if self.visible_area.w == self.page_area.w then
|
||||
y_pan_off = self.visible_area.h * diff
|
||||
|
||||
@@ -21,7 +21,7 @@ local function LvDEBUG(lv, ...)
|
||||
if isAndroid then
|
||||
android.LOGI("#"..line)
|
||||
else
|
||||
print(string.format("# %s %s", os.date("%x-%X"), line))
|
||||
io.stdout:write(string.format("# %s %s\n", os.date("%x-%X"), line))
|
||||
io.stdout:flush()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,10 +9,14 @@ local Device = {
|
||||
screen_saver_mode = false,
|
||||
charging_mode = false,
|
||||
survive_screen_saver = false,
|
||||
is_cover_closed = false,
|
||||
model = nil,
|
||||
powerd = nil,
|
||||
screen = nil,
|
||||
input = nil,
|
||||
-- For Kobo, wait at least 15 seconds before calling suspend script. Otherwise, suspend might
|
||||
-- fail and the battery will be drained while we are in screensaver mode
|
||||
suspend_wait_timeout = 15,
|
||||
|
||||
-- hardware feature tests: (these are functions!)
|
||||
hasKeyboard = no,
|
||||
@@ -113,12 +117,48 @@ function Device:outofScreenSaver()
|
||||
self.screen_saver_mode = false
|
||||
end
|
||||
|
||||
function Device:rescheduleSuspend()
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:unschedule(self.suspend)
|
||||
UIManager:scheduleIn(self.suspend_wait_timeout, self.suspend)
|
||||
end
|
||||
|
||||
-- ONLY used for Kobo and PocketBook devices
|
||||
function Device:onPowerEvent(ev)
|
||||
local Screensaver = require("ui/screensaver")
|
||||
local network_manager = require("ui/network/manager")
|
||||
if (ev == "Power" or ev == "Suspend") and not self.screen_saver_mode then
|
||||
if self.screen_saver_mode then
|
||||
if ev == "Power" or ev == "Resume" then
|
||||
if self.is_cover_closed then
|
||||
-- don't let power key press wake up device when the cover is in closed state
|
||||
self:rescheduleSuspend()
|
||||
else
|
||||
DEBUG("Resuming...")
|
||||
require("ui/uimanager"):unschedule(self.suspend)
|
||||
local network_manager = require("ui/network/manager")
|
||||
if network_manager.wifi_was_on and G_reader_settings:nilOrTrue("auto_restore_wifi") then
|
||||
network_manager.restoreWifiAsync()
|
||||
end
|
||||
self:resume()
|
||||
require("ui/screensaver"):close()
|
||||
-- restore to previous rotation mode
|
||||
self.screen:setRotationMode(self.orig_rotation_mode)
|
||||
if self:needsScreenRefreshAfterResume() then
|
||||
self.screen:refreshFull()
|
||||
end
|
||||
self.screen_saver_mode = false
|
||||
self.powerd:refreshCapacity()
|
||||
self.powerd:afterResume()
|
||||
end
|
||||
elseif ev == "Suspend" then
|
||||
-- Already in screen saver mode, no need to update UI/state before
|
||||
-- suspending the hardware. This usually happens when sleep cover
|
||||
-- is closed after the device was sent to suspend state.
|
||||
DEBUG("Already in screen saver mode, suspending...")
|
||||
self:rescheduleSuspend()
|
||||
end
|
||||
-- else we we not in screensaver mode
|
||||
elseif ev == "Power" or ev == "Suspend" then
|
||||
self.powerd:beforeSuspend()
|
||||
local network_manager = require("ui/network/manager")
|
||||
if network_manager.wifi_was_on then
|
||||
network_manager:releaseIP()
|
||||
network_manager:turnOffWifi()
|
||||
@@ -131,27 +171,10 @@ function Device:onPowerEvent(ev)
|
||||
-- always suspend in portrait mode
|
||||
self.orig_rotation_mode = self.screen:getRotationMode()
|
||||
self.screen:setRotationMode(0)
|
||||
Screensaver:show()
|
||||
require("ui/screensaver"):show()
|
||||
self.screen:refreshFull()
|
||||
self.screen_saver_mode = true
|
||||
UIManager:scheduleIn(10, self.suspend)
|
||||
elseif (ev == "Power" or ev == "Resume") and self.screen_saver_mode then
|
||||
DEBUG("Resuming...")
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:unschedule(self.suspend)
|
||||
if network_manager.wifi_was_on and G_reader_settings:nilOrTrue("auto_restore_wifi") then
|
||||
network_manager.restoreWifiAsync()
|
||||
end
|
||||
self:resume()
|
||||
Screensaver:close()
|
||||
-- restore to previous rotation mode
|
||||
self.screen:setRotationMode(self.orig_rotation_mode)
|
||||
if self:needsScreenRefreshAfterResume() then
|
||||
self.screen:refreshFull()
|
||||
end
|
||||
self.screen_saver_mode = false
|
||||
self.powerd:refreshCapacity()
|
||||
self.powerd:afterResume()
|
||||
UIManager:scheduleIn(self.suspend_wait_timeout, self.suspend)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -160,8 +160,7 @@ function GestureDetector:getPath(slot)
|
||||
local y_diff = self.last_tevs[slot].y - self.first_tevs[slot].y
|
||||
local direction = nil
|
||||
local distance = math.sqrt(x_diff*x_diff + y_diff*y_diff)
|
||||
if x_diff == 0 and y_diff == 0 then
|
||||
else
|
||||
if x_diff ~= 0 or y_diff ~= 0 then
|
||||
local v_direction = y_diff < 0 and "north" or "south"
|
||||
local h_direction = x_diff < 0 and "west" or "east"
|
||||
if math.abs(y_diff) > 0.577*math.abs(x_diff)
|
||||
|
||||
@@ -265,6 +265,10 @@ function Input:handleKeyBoardEv(ev)
|
||||
return
|
||||
end
|
||||
|
||||
if type(keycode) == "function" then
|
||||
return keycode(ev)
|
||||
end
|
||||
|
||||
-- take device rotation into account
|
||||
if self.rotation_map[self.device.screen:getRotationMode()][keycode] then
|
||||
keycode = self.rotation_map[self.device.screen:getRotationMode()][keycode]
|
||||
@@ -275,15 +279,6 @@ function Input:handleKeyBoardEv(ev)
|
||||
return keycode
|
||||
end
|
||||
|
||||
-- Kobo sleep
|
||||
if keycode == "Power_SleepCover" then
|
||||
if ev.value == EVENT_VALUE_KEY_PRESS then
|
||||
return "Suspend"
|
||||
else
|
||||
return "Resume"
|
||||
end
|
||||
end
|
||||
|
||||
if keycode == "Power" then
|
||||
-- Kobo generates Power keycode only, we need to decide whether it's
|
||||
-- power-on or power-off ourselves.
|
||||
@@ -300,10 +295,6 @@ function Input:handleKeyBoardEv(ev)
|
||||
end
|
||||
end
|
||||
|
||||
if ev.value == EVENT_VALUE_KEY_RELEASE and keycode == "Light" then
|
||||
return keycode
|
||||
end
|
||||
|
||||
-- handle modifier keys
|
||||
if self.modifiers[keycode] ~= nil then
|
||||
if ev.value == EVENT_VALUE_KEY_PRESS then
|
||||
@@ -538,6 +529,14 @@ function Input:cleanAbsxy()
|
||||
self:setCurrentMtSlot("abs_y", nil)
|
||||
end
|
||||
|
||||
function Input:isEvKeyPress(ev)
|
||||
return ev.value == EVENT_VALUE_KEY_PRESS
|
||||
end
|
||||
|
||||
function Input:isEvKeyRelease(ev)
|
||||
return ev.value == EVENT_VALUE_KEY_RELEASE
|
||||
end
|
||||
|
||||
|
||||
-- main event handling:
|
||||
|
||||
|
||||
@@ -118,16 +118,30 @@ function Kobo:init()
|
||||
self.input = require("device/input"):new{
|
||||
device = self,
|
||||
event_map = {
|
||||
[90] = "Light",
|
||||
[59] = function(ev)
|
||||
if self.input:isEvKeyPress(ev) then
|
||||
return "SleepCoverClosed"
|
||||
else
|
||||
return "SleepCoverOpened"
|
||||
end
|
||||
end,
|
||||
[90] = function(ev)
|
||||
if self.input:isEvKeyRelease(ev) then
|
||||
return "Light"
|
||||
end
|
||||
end,
|
||||
[330] = function(ev)
|
||||
if self.input:isEvKeyPress(ev) then
|
||||
return "USBPlugIn"
|
||||
else
|
||||
return "USBPlugOut"
|
||||
end
|
||||
end,
|
||||
[102] = "Home",
|
||||
[116] = "Power",
|
||||
}
|
||||
}
|
||||
|
||||
if not G_reader_settings:readSetting("ignore_power_sleepcover") then
|
||||
self.input.event_map[59] = "Power_SleepCover"
|
||||
end
|
||||
|
||||
Generic.init(self)
|
||||
|
||||
self.input.open("/dev/input/event0") -- Light button and sleep slider
|
||||
@@ -156,6 +170,38 @@ function Kobo:init()
|
||||
self:initEventAdjustHooks()
|
||||
end
|
||||
end
|
||||
|
||||
-- TODO: get rid of KOBO_LIGHT_ON_START
|
||||
local kobo_light_on_start = tonumber(KOBO_LIGHT_ON_START)
|
||||
if kobo_light_on_start then
|
||||
local new_intensity
|
||||
local is_frontlight_on
|
||||
if kobo_light_on_start > 0 then
|
||||
new_intensity = math.min(kobo_light_on_start, 100)
|
||||
is_frontlight_on = true
|
||||
elseif kobo_light_on_start == 0 then
|
||||
is_frontlight_on = false
|
||||
elseif kobo_light_on_start == -2 then
|
||||
local NickelConf = require("device/kobo/nickel_conf")
|
||||
new_intensity = NickelConf.frontLightLevel.get()
|
||||
is_frontlight_on = NickelConf.frontLightState:get()
|
||||
if is_frontlight_on == nil then
|
||||
-- this device does not support frontlight toggle,
|
||||
-- we set the value based on frontlight intensity.
|
||||
if new_intensity > 0 then
|
||||
is_frontlight_on = true
|
||||
else
|
||||
is_frontlight_on = false
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Since this is kobo-specific, we save all values in settings here
|
||||
-- and let the code (reader.lua) pick it up later during bootstrap.
|
||||
if new_intensity then
|
||||
G_reader_settings:saveSetting("frontlight_intensity", new_intensity)
|
||||
end
|
||||
G_reader_settings:saveSetting("is_frontlight_on", is_frontlight_on)
|
||||
end
|
||||
end
|
||||
|
||||
function Kobo:initNetworkManager(NetworkMgr)
|
||||
@@ -309,7 +355,7 @@ elseif codename == "alyssum" then
|
||||
elseif codename == "pika" then
|
||||
return KoboPika
|
||||
elseif codename == "daylight" then
|
||||
return KoboDaylight
|
||||
return KoboDaylight
|
||||
else
|
||||
error("unrecognized Kobo model "..codename)
|
||||
end
|
||||
|
||||
@@ -86,9 +86,34 @@ function UIManager:init()
|
||||
self.event_handlers["Suspend"]()
|
||||
end
|
||||
end
|
||||
if not G_reader_settings:readSetting("ignore_power_sleepcover") then
|
||||
self.event_handlers["SleepCoverClosed"] = function()
|
||||
Device.is_cover_closed = true
|
||||
self.event_handlers["Suspend"]()
|
||||
end
|
||||
self.event_handlers["SleepCoverOpened"] = function()
|
||||
Device.is_cover_closed = false
|
||||
self.event_handlers["Resume"]()
|
||||
end
|
||||
else
|
||||
-- Closing/opening the cover will still wake up the device, so we
|
||||
-- need to put it back to sleep if we are in screen saver mode
|
||||
self.event_handlers["SleepCoverClosed"] = function()
|
||||
if Device.screen_saver_mode then
|
||||
self.event_handlers["Suspend"]()
|
||||
end
|
||||
end
|
||||
self.event_handlers["SleepCoverOpened"] = self.event_handlers["SleepCoverClosed"]
|
||||
end
|
||||
self.event_handlers["Light"] = function()
|
||||
Device:getPowerDevice():toggleFrontlight()
|
||||
end
|
||||
self.event_handlers["USBPlugIn"] = function()
|
||||
if Device.screen_saver_mode then
|
||||
self.event_handlers["Suspend"]()
|
||||
end
|
||||
end
|
||||
self.event_handlers["USBPlugOut"] = self.event_handlers["USBPlugIn"]
|
||||
self.event_handlers["__default__"] = function(input_event)
|
||||
if Device.screen_saver_mode then
|
||||
-- Suspension in Kobo can be interrupted by screen updates. We
|
||||
@@ -99,37 +124,6 @@ function UIManager:init()
|
||||
self:sendEvent(input_event)
|
||||
end
|
||||
end
|
||||
local kobo_light_on_start = tonumber(KOBO_LIGHT_ON_START)
|
||||
if kobo_light_on_start then
|
||||
local new_intensity
|
||||
local is_frontlight_on
|
||||
if kobo_light_on_start > 0 then
|
||||
new_intensity = math.min(kobo_light_on_start, 100)
|
||||
is_frontlight_on = true
|
||||
elseif kobo_light_on_start == 0 then
|
||||
is_frontlight_on = false
|
||||
elseif kobo_light_on_start == -2 then
|
||||
local NickelConf = require("device/kobo/nickel_conf")
|
||||
new_intensity = NickelConf.frontLightLevel.get()
|
||||
is_frontlight_on = NickelConf.frontLightState:get()
|
||||
if is_frontlight_on == nil then
|
||||
-- this device does not support frontlight toggle,
|
||||
-- we set the value based on frontlight intensity.
|
||||
if new_intensity > 0 then
|
||||
is_frontlight_on = true
|
||||
else
|
||||
is_frontlight_on = false
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Since this kobo-specific, we save all values in settings here
|
||||
-- and let the code (reader.lua) pick it up later during bootstrap.
|
||||
if new_intensity then
|
||||
G_reader_settings:saveSetting("frontlight_intensity",
|
||||
new_intensity)
|
||||
end
|
||||
G_reader_settings:saveSetting("is_frontlight_on", is_frontlight_on)
|
||||
end
|
||||
elseif Device:isKindle() then
|
||||
self.event_handlers["IntoSS"] = function()
|
||||
Device:intoScreenSaver()
|
||||
|
||||
@@ -10,7 +10,7 @@ Example:
|
||||
title = _("Dialog title"),
|
||||
input = "default value",
|
||||
input_hint = "hint text",
|
||||
input_type = "text",
|
||||
input_type = "string",
|
||||
-- text_type = "password",
|
||||
buttons = {
|
||||
{
|
||||
@@ -26,7 +26,8 @@ Example:
|
||||
-- triggered after user press the enter key from keyboard
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
print('Got user input:', sample_input:getInputText())
|
||||
print('Got user input as raw text:', sample_input:getInputText())
|
||||
print('Got user input as value:', sample_input:getInputValue())
|
||||
end,
|
||||
},
|
||||
}
|
||||
@@ -177,6 +178,15 @@ function InputDialog:getInputText()
|
||||
return self._input_widget:getText()
|
||||
end
|
||||
|
||||
function InputDialog:getInputValue()
|
||||
local text = self:getInputText()
|
||||
if self.input_type == "number" then
|
||||
return tonumber(text)
|
||||
else
|
||||
return text
|
||||
end
|
||||
end
|
||||
|
||||
function InputDialog:setInputText(text)
|
||||
self._input_widget:setText(text)
|
||||
end
|
||||
|
||||
1
kodev
1
kodev
@@ -329,6 +329,7 @@ OPTIONS:
|
||||
test_path="${test_path}/$2"
|
||||
fi
|
||||
|
||||
echo "Runing tests in" ${test_path}
|
||||
busted --lua="./luajit" ${opts} \
|
||||
--no-auto-insulate \
|
||||
--lazy \
|
||||
|
||||
@@ -41,8 +41,21 @@ describe("device module", function()
|
||||
|
||||
describe("kobo", function()
|
||||
local TimeVal
|
||||
local NickelConf
|
||||
setup(function()
|
||||
TimeVal = require("ui/timeval")
|
||||
NickelConf = require("device/kobo/nickel_conf")
|
||||
end)
|
||||
|
||||
before_each(function()
|
||||
stub(NickelConf.frontLightLevel, "get")
|
||||
NickelConf.frontLightLevel.get.returns(0)
|
||||
stub(NickelConf.frontLightState, "get")
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
NickelConf.frontLightLevel.get:revert()
|
||||
NickelConf.frontLightState.get:revert()
|
||||
end)
|
||||
|
||||
it("should initialize properly on Kobo dahlia", function()
|
||||
@@ -51,7 +64,6 @@ describe("device module", function()
|
||||
|
||||
kobo_dev:init()
|
||||
assert.is.same("Kobo_dahlia", kobo_dev.model)
|
||||
|
||||
end)
|
||||
|
||||
it("should setup eventAdjustHooks properly for input in trilogy", function()
|
||||
@@ -149,10 +161,7 @@ describe("device module", function()
|
||||
local sample_pdf = "spec/front/unit/data/tall.pdf"
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local Device = require("device")
|
||||
local NickelConf = require("device/kobo/nickel_conf")
|
||||
|
||||
stub(NickelConf.frontLightLevel, "get")
|
||||
stub(NickelConf.frontLightState, "get")
|
||||
NickelConf.frontLightLevel.get.returns(1)
|
||||
NickelConf.frontLightState.get.returns(0)
|
||||
|
||||
@@ -175,8 +184,6 @@ describe("device module", function()
|
||||
Device.suspend:revert()
|
||||
Device.powerd.beforeSuspend:revert()
|
||||
Device.isKobo:revert()
|
||||
NickelConf.frontLightLevel.get:revert()
|
||||
NickelConf.frontLightState.get:revert()
|
||||
readerui.onFlushSettings:revert()
|
||||
UIManager._startAutoSuspend = nil
|
||||
UIManager._stopAutoSuspend = nil
|
||||
|
||||
Reference in New Issue
Block a user