Browse Source

Minor util & ffi/util cleanups (#6657)

reviewable/pr6658/r1
NiLuJe 1 year ago
committed by GitHub
parent
commit
99045b4311
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 88 additions and 95 deletions
  1. +1
    -1
      frontend/apps/filemanager/filemanager.lua
  2. +1
    -1
      frontend/apps/filemanager/filemanagercollection.lua
  3. +3
    -3
      frontend/apps/filemanager/filemanagermenu.lua
  4. +1
    -1
      frontend/apps/filemanager/filemanagershortcuts.lua
  5. +1
    -1
      frontend/apps/reader/modules/readerdictionary.lua
  6. +1
    -1
      frontend/apps/reader/readerui.lua
  7. +3
    -3
      frontend/device/android/device.lua
  8. +5
    -6
      frontend/device/kobo/powerd.lua
  9. +13
    -16
      frontend/document/credocument.lua
  10. +3
    -4
      frontend/readcollection.lua
  11. +1
    -1
      frontend/readhistory.lua
  12. +2
    -2
      frontend/ui/elements/menu_keyboard_layout.lua
  13. +3
    -3
      frontend/ui/network/wpa_supplicant.lua
  14. +1
    -1
      frontend/ui/translator.lua
  15. +2
    -2
      frontend/ui/widget/keyboardlayoutdialog.lua
  16. +2
    -3
      frontend/ui/widget/menu.lua
  17. +4
    -4
      frontend/ui/widget/virtualkeyboard.lua
  18. +4
    -4
      plugins/calibre.koplugin/wireless.lua
  19. +22
    -23
      plugins/coverbrowser.koplugin/bookinfomanager.lua
  20. +5
    -4
      plugins/coverbrowser.koplugin/covermenu.lua
  21. +2
    -3
      plugins/evernote.koplugin/main.lua
  22. +1
    -1
      plugins/gestures.koplugin/main.lua
  23. +3
    -3
      plugins/profiles.koplugin/main.lua
  24. +3
    -3
      plugins/statistics.koplugin/main.lua
  25. +1
    -1
      plugins/terminal.koplugin/main.lua

+ 1
- 1
frontend/apps/filemanager/filemanager.lua View File

@ -45,7 +45,7 @@ local util = require("util")
local _ = require("gettext")
local C_ = _.pgettext
local Screen = Device.screen
local T = require("ffi/util").template
local T = BaseUtil.template
local FileManager = InputContainer:extend{
title = _("KOReader"),

+ 1
- 1
frontend/apps/filemanager/filemanagercollection.lua View File

@ -11,7 +11,7 @@ local Screen = require("device").screen
local BaseUtil = require("ffi/util")
local util = require("util")
local _ = require("gettext")
local T = require("ffi/util").template
local T = BaseUtil.template
local FileManagerCollection = InputContainer:extend{
coll_menu_title = _("Favorites"),

+ 3
- 3
frontend/apps/filemanager/filemanagermenu.lua View File

@ -4,6 +4,7 @@ local CloudStorage = require("apps/cloudstorage/cloudstorage")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Event = require("ui/event")
local FFIUtil = require("ffi/util")
local InputContainer = require("ui/widget/container/inputcontainer")
local PluginLoader = require("pluginloader")
local SetDefaults = require("apps/filemanager/filemanagersetdefaults")
@ -14,7 +15,7 @@ local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local util = require("util")
local _ = require("gettext")
local T = require("ffi/util").template
local T = FFIUtil.template
local FileManagerMenu = InputContainer:extend{
tab_item_table = nil,
@ -246,11 +247,10 @@ function FileManagerMenu:setUpdateItemTable()
UIManager:show(ConfirmBox:new{
text = _("Clear cache/ and cr3cache/ ?"),
ok_callback = function()
local purgeDir = require("ffi/util").purgeDir
local DataStorage = require("datastorage")
local cachedir = DataStorage:getDataDir() .. "/cache"
if lfs.attributes(cachedir, "mode") == "directory" then
purgeDir(cachedir)
FFIUtil.purgeDir(cachedir)
end
lfs.mkdir(cachedir)
-- Also remove from Cache objet references to

+ 1
- 1
frontend/apps/filemanager/filemanagershortcuts.lua View File

@ -8,7 +8,7 @@ local Screen = require("device").screen
local UIManager = require("ui/uimanager")
local util = require("ffi/util")
local _ = require("gettext")
local T = require("ffi/util").template
local T = util.template
local FileManagerShortcuts = InputContainer:extend{}

+ 1
- 1
frontend/apps/reader/modules/readerdictionary.lua View File

@ -19,7 +19,7 @@ local logger = require("logger")
local util = require("util")
local _ = require("gettext")
local Screen = Device.screen
local T = require("ffi/util").template
local T = ffiUtil.template
-- We'll store the list of available dictionaries as a module local
-- so we only have to look for them on the first :init()

+ 1
- 1
frontend/apps/reader/readerui.lua View File

@ -59,7 +59,7 @@ local logger = require("logger")
local util = require("util")
local _ = require("gettext")
local Screen = require("device").screen
local T = require("ffi/util").template
local T = ffiUtil.template
local ReaderUI = InputContainer:new{
name = "ReaderUI",

+ 3
- 3
frontend/device/android/device.lua View File

@ -1,3 +1,4 @@
local FFIUtil = require("ffi/util")
local Generic = require("device/generic/device")
local A, android = pcall(require, "android") -- luacheck: ignore
local Geom = require("ui/geometry")
@ -7,7 +8,7 @@ local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local util = require("util")
local _ = require("gettext")
local T = require("ffi/util").template
local T = FFIUtil.template
local function yes() return true end
local function no() return false end
@ -386,12 +387,11 @@ local function processEvents()
end
function Device:showLightDialog()
local usleep = require("ffi/util").usleep
local title = android.isEink() and _("Frontlight settings") or _("Light settings")
android.lights.showDialog(title, _("Brightness"), _("Warmth"), _("OK"), _("Cancel"))
repeat
processEvents() -- swallow all events, including the last one
usleep(25000) -- sleep 25ms before next check if dialog was quit
FFIUtil.usleep(25000) -- sleep 25ms before next check if dialog was quit
until (android.lights.dialogState() ~= C.ALIGHTS_DIALOG_OPENED)
local GestureDetector = require("device/gesturedetector")

+ 5
- 6
frontend/device/kobo/powerd.lua View File

@ -2,6 +2,7 @@ local BasePowerD = require("device/generic/powerd")
local NickelConf = require("device/kobo/nickel_conf")
local PluginShare = require("pluginshare")
local SysfsLight = require ("device/sysfs_light")
local ffiUtil = require("ffi/util")
local batt_state_folder =
"/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/"
@ -324,15 +325,14 @@ function KoboPowerD:turnOffFrontlightHW()
if not self:isFrontlightOnHW() then
return
end
local util = require("ffi/util")
util.runInSubProcess(function()
ffiUtil.runInSubProcess(function()
for i = 1,5 do
self:_setIntensity(math.floor(self.fl_intensity - ((self.fl_intensity / 5) * i)))
--- @note: Newer devices appear to block slightly longer on FL ioctls/sysfs, so only sleep on older devices,
--- otherwise we get a jump and not a ramp ;).
if not self.device:hasNaturalLight() then
if (i < 5) then
util.usleep(35 * 1000)
ffiUtil.usleep(35 * 1000)
end
end
end
@ -364,15 +364,14 @@ function KoboPowerD:turnOnFrontlightHW()
if self:isFrontlightOnHW() then
return
end
local util = require("ffi/util")
util.runInSubProcess(function()
ffiUtil.runInSubProcess(function()
for i = 1,5 do
self:_setIntensity(math.ceil(self.fl_min + ((self.fl_intensity / 5) * i)))
--- @note: Newer devices appear to block slightly longer on FL ioctls/sysfs, so only sleep on older devices,
--- otherwise we get a jump and not a ramp ;).
if not self.device:hasNaturalLight() then
if (i < 5) then
util.usleep(35 * 1000)
ffiUtil.usleep(35 * 1000)
end
end
end

+ 13
- 16
frontend/document/credocument.lua View File

@ -2,6 +2,7 @@ local Blitbuffer = require("ffi/blitbuffer")
local CanvasContext = require("document/canvascontext")
local DataStorage = require("datastorage")
local Document = require("document/document")
local FFIUtil = require("ffi/util")
local FontList = require("fontlist")
local Geom = require("ui/geometry")
local RenderImage = require("ui/renderimage")
@ -420,14 +421,16 @@ function CreDocument:drawCurrentView(target, x, y, rect, pos)
-- We also honor the current smooth scaling setting,
-- as well as the global SW dithering setting.
-- local start_clock = os.clock()
--local start_ts = FFIUtil.getTimestamp()
self._drawn_images_count, self._drawn_images_surface_ratio =
self._document:drawCurrentPage(self.buffer, self.render_color, Screen.night_mode and self._nightmode_images, self._smooth_scaling, Screen.sw_dithering)
-- print(string.format("CreDocument:drawCurrentView: Rendering took %9.3f ms", (os.clock() - start_clock) * 1000))
--local end_ts = FFIUtil.getTimestamp()
--print(string.format("CreDocument:drawCurrentView: Rendering took %9.3f ms", (end_ts - start_ts) * 1000))
-- start_clock = os.clock()
--start_ts = FFIUtil.getTimestamp()
target:blitFrom(self.buffer, x, y, 0, 0, rect.w, rect.h)
-- print(string.format("CreDocument:drawCurrentView: Blitting took %9.3f ms", (os.clock() - start_clock) * 1000))
--end_ts = FFIUtil.getTimestamp()
--print(string.format("CreDocument:drawCurrentView: Blitting took %9.3f ms", (end_ts - start_ts) * 1000))
end
function CreDocument:drawCurrentViewByPos(target, x, y, rect, pos)
@ -1137,20 +1140,14 @@ function CreDocument:setupCallCache()
end
local no_op = function() end
local getTime = no_op
local addStatMiss = no_op
local addStatHit = no_op
local dumpStats = no_op
if do_stats then
-- cache statistics
self._call_cache_stats = {}
local _gettime = require("ffi/util").gettime
getTime = function()
local secs, usecs = _gettime()
return secs + usecs/1000000
end
addStatMiss = function(name, starttime, not_cached)
local duration = getTime() - starttime
local duration = FFIUtil.getTimestamp() - starttime
if not self._call_cache_stats[name] then
self._call_cache_stats[name] = {0, 0.0, 1, duration, not_cached}
else
@ -1160,7 +1157,7 @@ function CreDocument:setupCallCache()
end
end
addStatHit = function(name, starttime)
local duration = getTime() - starttime
local duration = FFIUtil.getTimestamp() - starttime
if not duration then duration = 0.0 end
if not self._call_cache_stats[name] then
self._call_cache_stats[name] = {1, duration, 0, 0.0}
@ -1351,7 +1348,7 @@ function CreDocument:setupCallCache()
elseif cache_by_tag then
is_cached = true
self[name] = function(...)
local starttime = getTime()
local starttime = FFIUtil.getTimestamp()
local cache_key = name .. asString(select(2, ...))
local results = self._callCacheTagGet(cache_key)
if results then
@ -1372,7 +1369,7 @@ function CreDocument:setupCallCache()
elseif cache_global then
is_cached = true
self[name] = function(...)
local starttime = getTime()
local starttime = FFIUtil.getTimestamp()
local cache_key = name .. asString(select(2, ...))
local results = self._callCacheGet(cache_key)
if results then
@ -1392,7 +1389,7 @@ function CreDocument:setupCallCache()
if do_stats_include_not_cached and not is_cached then
local func2 = self[name] -- might already be wrapped
self[name] = function(...)
local starttime = getTime()
local starttime = FFIUtil.getTimestamp()
local results = { func2(...) }
addStatMiss(name, starttime, true) -- not_cached = true
return unpack(results)
@ -1414,7 +1411,7 @@ function CreDocument:setupCallCache()
elseif current_buffer_tag ~= current_tag then
do_draw = true
end
local starttime = getTime()
local starttime = FFIUtil.getTimestamp()
if do_draw then
if do_log then logger.dbg("callCache: ########## drawCurrentView: full draw") end
CreDocument.drawCurrentView(_self, target, x, y, rect, pos)

+ 3
- 4
frontend/readcollection.lua View File

@ -1,8 +1,7 @@
local DataStorage = require("datastorage")
local FFIUtil = require("ffi/util")
local LuaSettings = require("luasettings")
local getFriendlySize = require("util").getFriendlySize
local lfs = require("libs/libkoreader-lfs")
local realpath = require("ffi/util").realpath
local util = require("util")
local DEFAULT_COLLECTION_NAME = "favorites"
@ -41,9 +40,9 @@ function ReadCollection:prepareList(collection_name)
table.insert(list, {
order = v.order,
text = v.file:gsub(".*/", ""),
file = realpath(v.file) or v.file, -- keep orig file path of deleted files
file = FFIUtil.realpath(v.file) or v.file, -- keep orig file path of deleted files
dim = not file_exists, -- "dim", as expected by Menu
mandatory = file_exists and getFriendlySize(lfs.attributes(v.file, "size") or 0),
mandatory = file_exists and util.getFriendlySize(lfs.attributes(v.file, "size") or 0),
callback = function()
local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(v.file)

+ 1
- 1
frontend/readhistory.lua View File

@ -22,7 +22,7 @@ local function buildEntry(input_time, input_file)
text = input_file:gsub(".*/", ""),
file = file_path,
dim = not file_exists, -- "dim", as expected by Menu
-- mandatory = file_exists and require("util").getFriendlySize(lfs.attributes(input_file, "size") or 0),
-- mandatory = file_exists and util.getFriendlySize(lfs.attributes(input_file, "size") or 0),
mandatory_func = function() -- Show the last read time (rather than file size)
local readerui_instance = require("apps/reader/readerui"):_getRunningInstance()
local currently_opened_file = readerui_instance and readerui_instance.document.file

+ 2
- 2
frontend/ui/elements/menu_keyboard_layout.lua View File

@ -1,10 +1,10 @@
local FFIUtil = require("ffi/util")
local Language = require("ui/language")
local VirtualKeyboard = require("ui/widget/virtualkeyboard")
local orderedPairs = require("ffi/util").orderedPairs
local sub_item_table = {}
for k, _ in orderedPairs(VirtualKeyboard.lang_to_keyboard_layout) do
for k, _ in FFIUtil.orderedPairs(VirtualKeyboard.lang_to_keyboard_layout) do
table.insert(sub_item_table, {
text_func = function()
local text = Language:getLanguageName(k)

+ 3
- 3
frontend/ui/network/wpa_supplicant.lua View File

@ -2,12 +2,12 @@
WPA client helper for Kobo.
]]
local FFIUtil = require("ffi/util")
local InfoMessage = require("ui/widget/infomessage")
local WpaClient = require('lj-wpaclient/wpaclient')
local UIManager = require("ui/uimanager")
local _ = require("gettext")
local T = require("ffi/util").template
local sleep = require("ffi/util").sleep
local T = FFIUtil.template
local CLIENT_INIT_ERR_MSG = _("Failed to initialize network control client: %1.")
@ -113,7 +113,7 @@ function WpaSupplicant:authenticateNetwork(network)
end
end
else
sleep(1)
FFIUtil.sleep(1)
cnt = cnt + 1
end
end

+ 1
- 1
frontend/ui/translator.lua View File

@ -17,7 +17,7 @@ local Screen = require("device").screen
local ffiutil = require("ffi/util")
local logger = require("logger")
local util = require("util")
local T = require("ffi/util").template
local T = ffiutil.template
local _ = require("gettext")
-- From https://cloud.google.com/translate/docs/languages

+ 2
- 2
frontend/ui/widget/keyboardlayoutdialog.lua View File

@ -5,6 +5,7 @@ This widget displays a keyboard layout dialog.
local Blitbuffer = require("ffi/blitbuffer")
local ButtonTable = require("ui/widget/buttontable")
local CenterContainer = require("ui/widget/container/centercontainer")
local FFIUtil = require("ffi/util")
local Font = require("ui/font")
local FrameContainer = require("ui/widget/container/framecontainer")
local Geom = require("ui/geometry")
@ -19,7 +20,6 @@ local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local _ = require("gettext")
local Screen = require("device").screen
local orderedPairs = require("ffi/util").orderedPairs
local KeyboardLayoutDialog = InputContainer:new{
is_always_active = true,
@ -56,7 +56,7 @@ function KeyboardLayoutDialog:init()
local buttons = {}
local radio_buttons = {}
for k, _ in orderedPairs(self.parent.keyboard.lang_to_keyboard_layout) do
for k, _ in FFIUtil.orderedPairs(self.parent.keyboard.lang_to_keyboard_layout) do
table.insert(radio_buttons, {
{
text = Language:getLanguageName(k),

+ 2
- 3
frontend/ui/widget/menu.lua View File

@ -31,7 +31,6 @@ local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local logger = require("logger")
local util = require("ffi/util")
local _ = require("gettext")
local Input = Device.input
local Screen = Device.screen
@ -734,7 +733,7 @@ function Menu:init()
callback = function()
for k, v in ipairs(self.item_table) do
--- @todo Support utf8 lowercase.
local filename = util.basename(v.path):lower()
local filename = FFIUtil.basename(v.path):lower()
local search_string = self.page_info_text.input_dialog:getInputText():lower()
local i, _ = filename:find(search_string)
if i == 1 and not v.is_go_up then
@ -953,7 +952,7 @@ function Menu:updatePageInfo(select_number)
end
-- update page information
if self.page_num > 1 then
self.page_info_text:setText(util.template(_("Page %1 of %2"), self.page, self.page_num))
self.page_info_text:setText(FFIUtil.template(_("Page %1 of %2"), self.page, self.page_num))
else
self.page_info_text:setText("");
end

+ 4
- 4
frontend/ui/widget/virtualkeyboard.lua View File

@ -3,6 +3,7 @@ local BottomContainer = require("ui/widget/container/bottomcontainer")
local CenterContainer = require("ui/widget/container/centercontainer")
local Device = require("device")
local Event = require("ui/event")
local FFIUtil = require("ffi/util")
local FocusManager = require("ui/widget/focusmanager")
local Font = require("ui/font")
local FrameContainer = require("ui/widget/container/framecontainer")
@ -20,7 +21,6 @@ local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local logger = require("logger")
local orderedPairs = require("ffi/util").orderedPairs
local util = require("util")
local Screen = Device.screen
@ -60,7 +60,7 @@ function VirtualKey:init()
local keyboard_layouts = G_reader_settings:readSetting("keyboard_layouts") or {}
local enabled = false
local next_layout = nil
for k, v in orderedPairs(keyboard_layouts) do
for k, v in FFIUtil.orderedPairs(keyboard_layouts) do
if enabled and v == true then
next_layout = k
break
@ -70,7 +70,7 @@ function VirtualKey:init()
end
end
if not next_layout then
for k, v in orderedPairs(keyboard_layouts) do
for k, v in FFIUtil.orderedPairs(keyboard_layouts) do
if enabled and v == true then
next_layout = k
break
@ -241,7 +241,7 @@ function VirtualKey:genkeyboardLayoutKeyChars()
end,
}
local index = 1
for k, v in orderedPairs(keyboard_layouts) do
for k, v in FFIUtil.orderedPairs(keyboard_layouts) do
if v == true then
key_chars[positions[index]] = string.sub(k, 1, 2)
key_chars[positions[index] .. "_func"] = function()

+ 4
- 4
plugins/calibre.koplugin/wireless.lua View File

@ -6,6 +6,7 @@
local BD = require("ui/bidi")
local CalibreMetadata = require("metadata")
local ConfirmBox = require("ui/widget/confirmbox")
local FFIUtil = require("ffi/util")
local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local InfoMessage = require("ui/widget/infomessage")
@ -13,11 +14,10 @@ local NetworkMgr = require("ui/network/manager")
local UIManager = require("ui/uimanager")
local logger = require("logger")
local rapidjson = require("rapidjson")
local sleep = require("ffi/util").sleep
local sha = require("ffi/sha2")
local util = require("util")
local _ = require("gettext")
local T = require("ffi/util").template
local T = FFIUtil.template
require("ffi/zeromq_h")
@ -257,9 +257,9 @@ end
function CalibreWireless:reconnect()
-- to use when something went wrong and we aren't in sync with calibre
sleep(1)
FFIUtil.sleep(1)
self:disconnect()
sleep(1)
FFIUtil.sleep(1)
self:connect()
end

+ 22
- 23
plugins/coverbrowser.koplugin/bookinfomanager.lua View File

@ -3,16 +3,16 @@ local Blitbuffer = require("ffi/blitbuffer")
local DataStorage = require("datastorage")
local Device = require("device")
local DocumentRegistry = require("document/documentregistry")
local FFIUtil = require("ffi/util")
local RenderImage = require("ui/renderimage")
local SQ3 = require("lua-ljsqlite3/init")
local UIManager = require("ui/uimanager")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local util = require("ffi/util")
local splitFilePathName = require("util").splitFilePathName
local util = require("util")
local _ = require("gettext")
local N_ = _.ngettext
local T = require("ffi/util").template
local T = FFIUtil.template
-- Util functions needed by this plugin, but that may be added to existing base/ffi/ files
local xutil = require("xutil")
@ -136,7 +136,7 @@ end
-- DB management
function BookInfoManager:getDbSize()
local file_size = lfs.attributes(self.db_location, "size") or 0
return require("util").getFriendlySize(file_size)
return util.getFriendlySize(file_size)
end
function BookInfoManager:createDB()
@ -263,7 +263,7 @@ end
-- Bookinfo management
function BookInfoManager:getBookInfo(filepath, get_cover)
local directory, filename = splitFilePathName(filepath)
local directory, filename = util.splitFilePathName(filepath)
-- CoverBrowser may be used by PathChooser, which will not filter out
-- files with unknown book extension. If not a supported extension,
@ -346,7 +346,7 @@ function BookInfoManager:extractBookInfo(filepath, cover_specs)
self.cre_cache_overriden = true
end
local directory, filename = splitFilePathName(filepath)
local directory, filename = util.splitFilePathName(filepath)
-- Initialize the new row that we will INSERT
local dbrow = { }
@ -482,7 +482,7 @@ end
function BookInfoManager:setBookInfoProperties(filepath, props)
-- If we need to set column=NULL, use props[column] = false (as
-- props[column] = nil would make column disappear from props)
local directory, filename = splitFilePathName(filepath)
local directory, filename = util.splitFilePathName(filepath)
self:openDbConnection()
-- Let's do multiple one-column UPDATE (easier than building
-- a multiple columns UPDATE)
@ -500,7 +500,7 @@ function BookInfoManager:setBookInfoProperties(filepath, props)
end
function BookInfoManager:deleteBookInfo(filepath)
local directory, filename = splitFilePathName(filepath)
local directory, filename = util.splitFilePathName(filepath)
self:openDbConnection()
local query = "DELETE FROM bookinfo WHERE directory=? AND filename=?"
local stmt = self.db_conn:prepare(query)
@ -542,7 +542,7 @@ function BookInfoManager:collectSubprocesses()
local i = 1
while i <= #self.subprocesses_pids do -- clean in-place
local pid = self.subprocesses_pids[i]
if util.isSubProcessDone(pid) then
if FFIUtil.isSubProcessDone(pid) then
table.remove(self.subprocesses_pids, i)
-- Prevent has been issued for each bg task spawn, we must allow for each death too.
UIManager:allowStandby()
@ -562,7 +562,7 @@ function BookInfoManager:collectSubprocesses()
-- the user has not left FileManager or changed page - that would
-- have caused a terminateBackgroundJobs() - if we're here, it's
-- that user has left reader in FileBrower and went away)
if util.gettime() > self.subprocesses_last_added_ts + self.subprocesses_killall_timeout_seconds then
if FFIUtil.getTimestamp() > self.subprocesses_last_added_ts + self.subprocesses_killall_timeout_seconds then
logger.warn("Some subprocesses were running for too long, killing them")
self:terminateBackgroundJobs()
-- we'll collect them next time we're run
@ -582,7 +582,7 @@ end
function BookInfoManager:terminateBackgroundJobs()
logger.dbg("terminating", #self.subprocesses_pids, "subprocesses")
for i=1, #self.subprocesses_pids do
util.terminateSubProcess(self.subprocesses_pids[i])
FFIUtil.terminateSubProcess(self.subprocesses_pids[i])
end
end
@ -610,7 +610,7 @@ function BookInfoManager:extractInBackground(files)
local cover_specs = files[idx].cover_specs
logger.dbg(" BG extracting:", filepath)
self:extractBookInfo(filepath, cover_specs)
util.usleep(100000) -- give main process 100ms of free cpu to do its processing
FFIUtil.usleep(100000) -- give main process 100ms of free cpu to do its processing
end
logger.dbg(" BG extraction done")
end
@ -618,7 +618,7 @@ function BookInfoManager:extractInBackground(files)
self.cleanup_needed = true -- so we will remove temporary cache directory created by subprocess
-- Run task in sub-process, and remember its pid
local task_pid = util.runInSubProcess(task)
local task_pid = FFIUtil.runInSubProcess(task)
if not task_pid then
logger.warn("Failed lauching background extraction sub-process (fork failed)")
return false -- let caller know it failed
@ -627,7 +627,7 @@ function BookInfoManager:extractInBackground(files)
-- counter on each task, and undo that inside collectSubprocesses() zombie reaper.
UIManager:preventStandby()
table.insert(self.subprocesses_pids, task_pid)
self.subprocesses_last_added_ts = util.gettime()
self.subprocesses_last_added_ts = FFIUtil.getTimestamp()
-- We need to collect terminated jobs pids (so they do not stay "zombies"
-- and fill linux processes table)
@ -651,13 +651,12 @@ function BookInfoManager:cleanUp()
end
if self.cleanup_needed then
logger.dbg("Removing directory", self.tmpcr3cache)
util.purgeDir(self.tmpcr3cache)
FFIUtil.purgeDir(self.tmpcr3cache)
self.cleanup_needed = false
end
end
local function findFilesInDir(path, recursive)
local stringStartsWith = require("util").stringStartsWith
local dirs = {path}
local files = {}
while #dirs ~= 0 do
@ -669,10 +668,10 @@ local function findFilesInDir(path, recursive)
local fullpath = d.."/"..f
local attributes = lfs.attributes(fullpath)
-- Don't traverse hidden folders if we're not showing them
if recursive and attributes.mode == "directory" and f ~= "." and f ~= ".." and (G_reader_settings:isTrue("show_hidden") or not stringStartsWith(f, ".")) then
if recursive and attributes.mode == "directory" and f ~= "." and f ~= ".." and (G_reader_settings:isTrue("show_hidden") or not util.stringStartsWith(f, ".")) then
table.insert(new_dirs, fullpath)
-- Always ignore macOS resource forks, too.
elseif attributes.mode == "file" and not stringStartsWith(f, "._") and DocumentRegistry:hasProvider(fullpath) then
elseif attributes.mode == "file" and not util.stringStartsWith(f, "._") and DocumentRegistry:hasProvider(fullpath) then
table.insert(files, fullpath)
end
end
@ -749,7 +748,7 @@ Do you want to prune the cache of removed books?]]
info = InfoMessage:new{text = summary}
UIManager:show(info)
UIManager:forceRePaint()
util.sleep(2) -- Let the user see that
FFIUtil.sleep(2) -- Let the user see that
break
end
end
@ -785,14 +784,14 @@ Do you want to prune the cache of removed books?]]
info = InfoMessage:new{text = T(N_("Found 1 book to index.", "Found %1 books to index.", #files), #files)}
UIManager:show(info)
UIManager:forceRePaint()
util.sleep(2) -- Let the user see that
FFIUtil.sleep(2) -- Let the user see that
else
local all_files = files
while true do
info = InfoMessage:new{text = T(_("Found %1 books.\nLooking for those not already present in the cache database…"), #all_files)}
UIManager:show(info)
UIManager:forceRePaint()
util.sleep(2) -- Let the user see that
FFIUtil.sleep(2) -- Let the user see that
completed, files = Trapper:dismissableRunInSubprocess(function()
files = {}
for _, filepath in pairs(all_files) do
@ -832,7 +831,7 @@ Do you want to prune the cache of removed books?]]
info = InfoMessage:new{text = T(N_("Found 1 book to index.", "Found %1 books to index."), #files)}
UIManager:show(info)
UIManager:forceRePaint()
util.sleep(2) -- Let the user see that
FFIUtil.sleep(2) -- Let the user see that
end
UIManager:close(info)
@ -850,7 +849,7 @@ Do you want to prune the cache of removed books?]]
while i <= nb_files do
local filepath = files[i]
local filename = util.basename(filepath)
local filename = FFIUtil.basename(filepath)
local orig_moved_offset = info.movable:getMovedOffset()
info:free()

+ 5
- 4
plugins/coverbrowser.koplugin/covermenu.lua View File

@ -9,6 +9,7 @@ local TextViewer = require("ui/widget/textviewer")
local UIManager = require("ui/uimanager")
local logger = require("logger")
local _ = require("gettext")
local util = require("util")
local BookInfoManager = require("bookinfomanager")
@ -293,7 +294,7 @@ function CoverMenu:updateItems(select_number)
-- Err, a summary table with no status entry? Should never happen...
local summary = { status = status }
-- Append the status entry to the existing summary...
require("util").tableMerge(docinfo.data.summary, summary)
util.tableMerge(docinfo.data.summary, summary)
else
-- No summary table at all, create a minimal one
local summary = { status = status }
@ -341,7 +342,7 @@ function CoverMenu:updateItems(select_number)
text = bookinfo.description and _("View book description") or _("No book description"),
enabled = bookinfo.description and true or false,
callback = function()
local description = require("util").htmlToPlainTextIfHtml(bookinfo.description)
local description = util.htmlToPlainTextIfHtml(bookinfo.description)
local textviewer = TextViewer:new{
title = bookinfo.title,
text = description,
@ -474,7 +475,7 @@ function CoverMenu:onHistoryMenuHold(item)
text = bookinfo.description and _("View book description") or _("No book description"),
enabled = bookinfo.description and true or false,
callback = function()
local description = require("util").htmlToPlainTextIfHtml(bookinfo.description)
local description = util.htmlToPlainTextIfHtml(bookinfo.description)
local textviewer = TextViewer:new{
title = bookinfo.title,
text = description,
@ -596,7 +597,7 @@ function CoverMenu:onCollectionsMenuHold(item)
text = bookinfo.description and _("View book description") or _("No book description"),
enabled = bookinfo.description and true or false,
callback = function()
local description = require("util").htmlToPlainTextIfHtml(bookinfo.description)
local description = util.htmlToPlainTextIfHtml(bookinfo.description)
local textviewer = TextViewer:new{
title = bookinfo.title,
text = description,

+ 2
- 3
plugins/evernote.koplugin/main.lua View File

@ -11,13 +11,12 @@ local logger = require("logger")
local util = require("ffi/util")
local Device = require("device")
local JoplinClient = require("JoplinClient")
local T = require("ffi/util").template
local T = util.template
local _ = require("gettext")
local N_ = _.ngettext
local slt2 = require('slt2')
local MyClipping = require("clip")
local json = require("json")
local realpath = require("ffi/util").realpath
local EvernoteExporter = InputContainer:new{
name = "evernote",
@ -642,7 +641,7 @@ function EvernoteExporter:exportClippings(clippings)
)
end
if (self.html_export or self.txt_export) and export_count > 0 then
msg = msg .. T(_("\nNotes can be found in %1/."), BD.dirpath(realpath(self.clipping_dir)))
msg = msg .. T(_("\nNotes can be found in %1/."), BD.dirpath(util.realpath(self.clipping_dir)))
end
UIManager:show(InfoMessage:new{ text = msg })
end

+ 1
- 1
plugins/gestures.koplugin/main.lua View File

@ -14,7 +14,7 @@ local LuaSettings = require("luasettings")
local Screen = require("device").screen
local UIManager = require("ui/uimanager")
local util = require("util")
local T = require("ffi/util").template
local T = FFIUtil.template
local _ = require("gettext")
local logger = require("logger")

+ 3
- 3
plugins/profiles.koplugin/main.lua View File

@ -1,14 +1,14 @@
local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
local Dispatcher = require("dispatcher")
local FFIUtil = require("ffi/util")
local InfoMessage = require("ui/widget/infomessage")
local InputDialog = require("ui/widget/inputdialog")
local LuaSettings = require("luasettings")
local UIManager = require("ui/uimanager")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local orderedPairs = require("ffi/util").orderedPairs
local _ = require("gettext")
local T = require("ffi/util").template
local T = FFIUtil.template
local Profiles = WidgetContainer:new{
name = "profiles",
@ -88,7 +88,7 @@ function Profiles:getSubMenuItems()
separator = true,
}
}
for k,v in orderedPairs(self.data) do
for k,v in FFIUtil.orderedPairs(self.data) do
local sub_items = {
{
text = _("Delete profile"),

+ 3
- 3
plugins/statistics.koplugin/main.lua View File

@ -4,6 +4,7 @@ local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
local Device = require("device")
local DocSettings = require("docsettings")
local FFIUtil = require("ffi/util")
local InfoMessage = require("ui/widget/infomessage")
local KeyValuePage = require("ui/widget/keyvaluepage")
local Math = require("optmath")
@ -19,10 +20,9 @@ local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local util = require("util")
local _ = require("gettext")
local joinPath = require("ffi/util").joinPath
local Screen = require("device").screen
local N_ = _.ngettext
local T = require("ffi/util").template
local T = FFIUtil.template
local statistics_dir = DataStorage:getDataDir() .. "/statistics/"
local db_location = DataStorage:getSettingsDir() .. "/statistics.sqlite3"
@ -1898,7 +1898,7 @@ end
function ReaderStatistics:importFromFile(base_path, item)
item = string.gsub(item, "^%s*(.-)%s*$", "%1") -- trim
if item ~= ".stat" then
local statistic_file = joinPath(base_path, item)
local statistic_file = FFIUtil.joinPath(base_path, item)
if lfs.attributes(statistic_file, "mode") == "directory" then
return
end

+ 1
- 1
plugins/terminal.koplugin/main.lua View File

@ -15,7 +15,7 @@ local util = require("ffi/util")
local _ = require("gettext")
local N_ = _.ngettext
local Screen = require("device").screen
local T = require("ffi/util").template
local T = util.template
local Terminal = WidgetContainer:new{
name = "terminal",

Loading…
Cancel
Save