From 10132d1c5972befd4e3e3acd0f4d3c3a4952d12c Mon Sep 17 00:00:00 2001 From: Cosmin Gorgovan Date: Sat, 1 Apr 2017 20:24:15 +0100 Subject: [PATCH] Disable the network asynchronously to avoid blocking the UI Noticeable latency between toggling the power switch and the device showing the screensaver has been tracked down to the two network manager calls. This change allows the screen to be updated first. Note that unloading the open source brcmfmac driver used on okreader is slower than unloading the proprietary driver shipped by Kobo, making this delay even more noticeable. self.suspend() is scheduled after the network manager calls to avoid race conditions. --- frontend/device/generic/device.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 32935aa13..973a011df 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -124,11 +124,6 @@ function Device:onPowerEvent(ev) -- 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() - end local UIManager = require("ui/uimanager") -- flushing settings first in case the screensaver takes too long time -- that flushing has no chance to run @@ -140,7 +135,14 @@ function Device:onPowerEvent(ev) require("ui/screensaver"):show("suspend", _("Sleeping")) self.screen:refreshFull() self.screen_saver_mode = true - UIManager:scheduleIn(self.suspend_wait_timeout, self.suspend) + UIManager:scheduleIn(0.1, function() + local network_manager = require("ui/network/manager") + if network_manager.wifi_was_on then + network_manager:releaseIP() + network_manager:turnOffWifi() + end + UIManager:scheduleIn(self.suspend_wait_timeout, self.suspend) + end) end end