[feat] Replace TimeVal (RIP) with time, fixed point time seconds (#8999)

This commit is contained in:
zwim
2022-05-05 21:00:22 +02:00
committed by GitHub
parent 54ead5fc88
commit 9b9cfe29a4
44 changed files with 1009 additions and 497 deletions

View File

@@ -13,11 +13,11 @@ local LuaData = require("luadata")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local NetworkMgr = require("ui/network/manager")
local SortWidget = require("ui/widget/sortwidget")
local TimeVal = require("ui/timeval")
local Trapper = require("ui/trapper")
local UIManager = require("ui/uimanager")
local ffiUtil = require("ffi/util")
local logger = require("logger")
local time = require("ui/time")
local util = require("util")
local _ = require("gettext")
local T = ffiUtil.template
@@ -111,7 +111,7 @@ function ReaderDictionary:init()
-- Allow quick interruption or dismiss of search result window
-- with tap if done before this delay. After this delay, the
-- result window is shown and dismiss prevented for a few 100ms
self.quick_dismiss_before_delay = TimeVal:new{ sec = 3, usec = 0 }
self.quick_dismiss_before_delay = time.s(3)
-- Gather info about available dictionaries
if not available_ifos then
@@ -931,9 +931,10 @@ function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, boxes,
self:showLookupInfo(word, self.lookup_msg_delay)
self._lookup_start_tv = UIManager:getTime()
self._lookup_start_time = UIManager:getTime()
local results = self:startSdcv(word, dict_names, fuzzy_search)
if results and results.lookup_cancelled and TimeVal:now() - self._lookup_start_tv <= self.quick_dismiss_before_delay then
if results and results.lookup_cancelled
and (time.now() - self._lookup_start_time) <= self.quick_dismiss_before_delay then
-- If interrupted quickly just after launch, don't display anything
-- (this might help avoiding refreshes and the need to dismiss
-- after accidental long-press when holding a device).
@@ -991,7 +992,8 @@ function ReaderDictionary:showDict(word, results, boxes, link)
self:dismissLookupInfo()
if results and results[1] then
UIManager:show(self.dict_window)
if not results.lookup_cancelled and self._lookup_start_tv and TimeVal:now() - self._lookup_start_tv > self.quick_dismiss_before_delay then
if not results.lookup_cancelled and self._lookup_start_time
and (time.now() - self._lookup_start_time) > self.quick_dismiss_before_delay then
-- If the search took more than a few seconds to be done, discard
-- queued and coming up events to avoid a voluntary dismissal
-- (because the user felt the result would not come) to kill the