WIP: Use background runner to restore wifi and check network state#3078
WIP: Use background runner to restore wifi and check network state#3078Hzj-jie wants to merge 18 commits intokoreader:masterfrom Hzj-jie:master
Conversation
|
The main menu itself? Can't say that feels unresponsive to me. |
|
Sorry, I mean the network menu. |
|
I guess I have a fast network (I'd better with my Ubiquiti equipment, even if it's the lowest grade), but that makes more sense. :-P |
|
Though this test is not exactly the same as what we are doing in the isOnline() function, by using mobile network, pinging www.example.com may need 500 milliseconds. I believe the performance would be even worse when mobile signal is weak. |
|
I'm not fond of having a ping being launched every 30 seconds in the background (if I undestand correctly https://github.com/koreader/koreader/pull/3078/files#diff-8a665adb55900a011d1c3928d7447e61R24), and this even when we know wifi is off. |
|
Btw, just seeing now that my idle emulator is logging every 2/3 seconds: Is that expected that your BackgroundRunner is scheduling itself when there is no job (like it seems to me) scheduled ? |
|
This is probably not the right place to stick this thought, but BackgroundRunner is probably the solution to #2540, isn't is? |
|
RE poire-z: yes, it runs once per two seconds. If there is no job, it quits. You may remove the log if it's annoying. Otherwise, it has no impact. UIManager itself polls much more frequently to receive user input. RE Frenzie: I think network connected event is broken for a while, which may impact the calibre connection. I have not gone deep to the code yet. |
I see. Nothing among the stuff done in https://github.com/koreader/koreader/blob/master/frontend/device/generic/device.lua#L177 (ifconfig, iwconfig) gives different results whether wifi is off or on or connected to a ssid ? Or something like |
That may be true on the emulator (with SDL, which has no wait with timeout function, and has to poll every 10ms), but it is not the case on kobo/kindle, where: I admit that getting out of this every 2 second isnt going to cost much, but it's a bit sad to do that when there is no work to do. A simpler alternative could be to just not launch |
|
Using ifconfig can get the wifi state, but it won't solve the problem: we need to poll the state of wifi instead of internet accessibility. I totally agree that moving background runner to the core would be a good choice, we can have a better control to the job queue without needing PluginShare. |
Sounds good! |
An other possibility for that, not involving BackgroundRunner, would be to extend TouchMenuItem to accept new attributes: --- a/frontend/ui/widget/touchmenu.lua
+++ b/frontend/ui/widget/touchmenu.lua
@@ function TouchMenuItem:init()
self.item_frame = FrameContainer:new{
width = self.dimen.w,
bordersize = 0,
color = Blitbuffer.COLOR_BLACK,
HorizontalGroup:new {
align = "center",
CenterContainer:new{
dimen = Geom:new{ w = checked_widget:getSize().w },
item_checkable and (
item_checked and checked_widget
or unchecked_widget
)
or empty_widget
},
TextWidget:new{
text = getMenuText(self.item),
fgcolor = item_enabled ~= false and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_GREY,
face = self.face,
},
},
}
+ if self.item.delayed_text_func then
+ UIManager:nextTick(function()
+ local new_text = self.item.delayed_text_func()
+ self.item_frame[1][2]:setText(new_text) -- self.item_frame's TextWidget
+ UIManager:setDirty(self.show_parent, function()
+ return "ui", self.item_frame[1][2].dimen
+ end)
+ end)
+ end
self[1] = self.item_frame
end
--- a/frontend/ui/network/manager.lua
+++ b/frontend/ui/network/manager.lua
@@ -77,9 +77,10 @@ end
function NetworkMgr:getWifiMenuTable()
return {
- text = _("Wi-Fi connection"),
+ text = _("Wi-Fi connection..."),
enabled_func = function() return Device:isKindle() or Device:isKobo() end,
- checked_func = function() return NetworkMgr:isOnline() end,
+ -- checked_func = function() return NetworkMgr:isOnline() end,
+ delayed_text_func = function() require("ffi/util").sleep(2) ; return NetworkMgr:isOnline() and "Wi-Fi connection online" or "Wi-Fi connection not online" end,
callback = function(menu)
local wifi_status = NetworkMgr:isOnline()
local complete_callback = function()So it would launch (but still block) the ping after menu is drawn, and you would see edit: and use a quick way ( |
| text = _("Poll network connectivity"), | ||
| callback = function() | ||
| UIManager:show(ConfirmBox:new{ | ||
| text = T(_("KOReader can actively poll network connectivity to \nDo you want to %1 it?"), |
There was a problem hiding this comment.
Do you want to %1 it? Is that safe for localization? It might be better to just write two full sentences, even if that seems redundant to a programmer.
But that's just something I thought of while looking at this in more detail. I actually started writing this comment because the first sentence brusquely ends at to. :-P
There was a problem hiding this comment.
I am working on moving the common logic into plugin templates. We can discuss this in #3137.
|
@poire-z I think that won't help to totally remove the blockage: when the delay_text_func is invoking in UIManager loop, any users input will be delayed. delay_text_func itself is a good idea, we can use it to update the text on menus for delay initialization. We are adding more features to KOReader, most of them requires IO operations. So moving all IO blocking operations out of UIManager loop to avoid unresponsiveness can significant improve the user experience. Since the delay of these operations are not predictable -- even writing DocSettings may block UI for seconds if a slow SD card is used or free storage is low.
|
|
I don't use KOSync nor OTA update, so can't say much about them - but I guess for an OTA update, I'd like to notice it's happening, get a grasp of the usual time it takes, so i can worry when it takes longer. |
|
The update thing is only about downloading. Considering you can go on reading for as long as you want before actually exiting it doesn't really make sense to block the UI while downloading. If it does then I reckon there should be a cancel button. |
|
I think most of the users are regular users, they won't care about threading model. But unresponsive UI is something unacceptable: for everything takes an unacceptable longer time, the only thing you can do is to force restart the device and eventually lost everything in DocSettings. |
|
@Hzj-jie Btw, we've had some discussion on the network in #3273 (comment) rather than #3160 where it should've been. |
|
Hi Guys, not sure if that's helpful but FYI in android we already have a function to check whether wifi is on or off |
|
Btw, BackgroundRunner is about external binaries but I'm not sure why I didn't mention that various libraries exist for making threaded stuff easy such as https://github.com/torch/threads |

This change should significantly improve the responsiveness of network menu. I.e. we do not need to ping the www.example.com when menu pops up.
I am still verifying this change on my device.