mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Fix WiFi status on Kindle
WiFi handling is handled asynchronously (deferred to lipc), so this is a bit clunkier than on devices where we handle WiFi ourselves... But, basically, try to honor the menu callback when toggling WiFi so that the status gets updated in the menu. Fix #4472
This commit is contained in:
@@ -17,27 +17,26 @@ local function kindleEnableWifi(toggle)
|
||||
end
|
||||
|
||||
local function isWifiUp()
|
||||
-- NOTE: Pilfered from Cervantes, c.f., #4380
|
||||
-- Possibly simpler and more compatible than the lipc approach ;).
|
||||
local file = io.open("/sys/class/net/wlan0/carrier", "rb")
|
||||
if not file then return 0 end
|
||||
local status = tonumber(file:read("*all")) or 0
|
||||
file:close()
|
||||
return status
|
||||
|
||||
--[[
|
||||
local status = 0
|
||||
local status
|
||||
local haslipc, lipc = pcall(require, "liblipclua")
|
||||
local lipc_handle = nil
|
||||
if haslipc and lipc then
|
||||
lipc_handle = lipc.init("com.github.koreader.networkmgr")
|
||||
end
|
||||
if lipc_handle then
|
||||
status = lipc_handle:get_int_property("com.lab126.wifid", "enable")
|
||||
status = lipc_handle:get_int_property("com.lab126.wifid", "enable") or 0
|
||||
lipc_handle:close()
|
||||
else
|
||||
-- NOTE: Pilfered from Cervantes, c.f., #4380
|
||||
-- Possibly race-y, if we're extremely unlucky and lipc drops WiFi between our open and our read...
|
||||
-- But then, if we're here, it's because we failed to acquire an lipc handle,
|
||||
-- so it's likely we've failed to do that earlier when trying to toggle WiFi, too...
|
||||
local file = io.open("/sys/class/net/wlan0/carrier", "rb")
|
||||
if not file then return 0 end
|
||||
status = tonumber(file:read("*all")) or 0
|
||||
file:close()
|
||||
end
|
||||
return status
|
||||
--]]
|
||||
end
|
||||
|
||||
--[[
|
||||
@@ -79,12 +78,24 @@ local Kindle = Generic:new{
|
||||
}
|
||||
|
||||
function Kindle:initNetworkManager(NetworkMgr)
|
||||
NetworkMgr.turnOnWifi = function()
|
||||
function NetworkMgr:turnOnWifi(complete_callback)
|
||||
kindleEnableWifi(1)
|
||||
-- NOTE: As we defer the actual work to lipc,
|
||||
-- we have no guarantee the WiFi state will have changed by the time kindleEnableWifi returns,
|
||||
-- so, delay the callback a bit...
|
||||
if complete_callback then
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:scheduleIn(1, complete_callback)
|
||||
end
|
||||
end
|
||||
|
||||
NetworkMgr.turnOffWifi = function()
|
||||
function NetworkMgr:turnOffWifi(complete_callback)
|
||||
kindleEnableWifi(0)
|
||||
-- NOTE: Same here...
|
||||
if complete_callback then
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:scheduleIn(1, complete_callback)
|
||||
end
|
||||
end
|
||||
|
||||
NetworkMgr.isWifiOn = function()
|
||||
|
||||
Reference in New Issue
Block a user