fix: disable network info menu when device is not connected

pull/2383/head
Qingping Hou 8 years ago
parent 171d40d287
commit bd43e59fe7

@ -58,7 +58,7 @@ function NetworkMgr:promptWifiOff(complete_callback)
}) })
end end
function NetworkMgr:getWifiStatus() function NetworkMgr:isOnline()
local socket = require("socket") local socket = require("socket")
return socket.dns.toip("www.example.com") ~= nil return socket.dns.toip("www.example.com") ~= nil
end end
@ -78,9 +78,9 @@ function NetworkMgr:getWifiMenuTable()
return { return {
text = _("Wi-Fi connection"), text = _("Wi-Fi connection"),
enabled_func = function() return Device:isKindle() or Device:isKobo() end, enabled_func = function() return Device:isKindle() or Device:isKobo() end,
checked_func = function() return NetworkMgr:getWifiStatus() end, checked_func = function() return NetworkMgr:isOnline() end,
callback = function(menu) callback = function(menu)
local wifi_status = NetworkMgr:getWifiStatus() local wifi_status = NetworkMgr:isOnline()
local complete_callback = function() local complete_callback = function()
-- notify touch menu to update item check state -- notify touch menu to update item check state
menu:updateItems() menu:updateItems()
@ -151,6 +151,8 @@ end
function NetworkMgr:getInfoMenuTable() function NetworkMgr:getInfoMenuTable()
return { return {
text = _("Network info"), text = _("Network info"),
-- TODO: also show network info when device is authenticated to router but offline
enabled_func = function() return self:isOnline() end,
callback = function(menu) callback = function(menu)
if Device.retrieveNetworkInfo then if Device.retrieveNetworkInfo then
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{

@ -229,7 +229,7 @@ function OTAManager:getOTAMenuTable()
{ {
text = _("Check for update"), text = _("Check for update"),
callback = function() callback = function()
if NetworkMgr:getWifiStatus() == false then if not NetworkMgr:isOnline() then
NetworkMgr:promptWifiOn() NetworkMgr:promptWifiOn()
else else
OTAManager:fetchAndProcessUpdate() OTAManager:fetchAndProcessUpdate()

@ -138,7 +138,7 @@ function EvernoteExporter:addToMainMenu(tab_item_table)
end end
function EvernoteExporter:login() function EvernoteExporter:login()
if NetworkMgr:getWifiStatus() == false then if not NetworkMgr:isOnline() then
NetworkMgr:promptWifiOn() NetworkMgr:promptWifiOn()
end end
self.login_dialog = LoginDialog:new{ self.login_dialog = LoginDialog:new{

@ -224,7 +224,7 @@ function KOSync:setCustomServer(server)
end end
function KOSync:login() function KOSync:login()
if NetworkMgr:getWifiStatus() == false then if not NetworkMgr:isOnline() then
NetworkMgr:promptWifiOn() NetworkMgr:promptWifiOn()
end end
self.login_dialog = LoginDialog:new{ self.login_dialog = LoginDialog:new{

Loading…
Cancel
Save