@ -112,14 +112,25 @@ function NetworkMgr:releaseIP() end
function NetworkMgr : restoreWifiAsync ( ) end
-- End of device specific methods
function NetworkMgr : promptWifiOn ( complete_callback )
function NetworkMgr : toggleWifiOn ( complete_callback , long_press )
self.wifi_was_on = true
G_reader_settings : makeTrue ( " wifi_was_on " )
self.wifi_toggle_long_press = long_press
self : turnOnWifi ( complete_callback )
end
function NetworkMgr : toggleWifiOff ( complete_callback )
self.wifi_was_on = false
G_reader_settings : makeFalse ( " wifi_was_on " )
self : turnOffWifi ( complete_callback )
end
function NetworkMgr : promptWifiOn ( complete_callback , long_press )
UIManager : show ( ConfirmBox : new {
text = _ ( " Do you want to turn on Wi-Fi? " ) ,
ok_text = _ ( " Turn on " ) ,
ok_callback = function ( )
self.wifi_was_on = true
G_reader_settings : makeTrue ( " wifi_was_on " )
self : turnOnWifi ( complete_callback )
self : toggleWifiOn ( complete_callback , long_press )
end ,
} )
end
@ -129,27 +140,21 @@ function NetworkMgr:promptWifiOff(complete_callback)
text = _ ( " Do you want to turn off Wi-Fi? " ) ,
ok_text = _ ( " Turn off " ) ,
ok_callback = function ( )
self.wifi_was_on = false
G_reader_settings : makeFalse ( " wifi_was_on " )
self : turnOffWifi ( complete_callback )
self : toggleWifiOff ( complete_callback )
end ,
} )
end
function NetworkMgr : promptWifi ( complete_callback )
function NetworkMgr : promptWifi ( complete_callback , long_press )
UIManager : show ( MultiConfirmBox : new {
text = _ ( " Wi-Fi is enabled, but you're currently not connected to a network. \n How would you like to proceed? " ) ,
choice1_text = _ ( " Turn Wi-Fi off " ) ,
choice1_callback = function ( )
self.wifi_was_on = false
G_reader_settings : makeFalse ( " wifi_was_on " )
self : turnOffWifi ( complete_callback )
self : toggleWifiOff ( complete_callback )
end ,
choice2_text = _ ( " Connect " ) ,
choice2_callback = function ( )
self.wifi_was_on = true
G_reader_settings : makeTrue ( " wifi_was_on " )
self : turnOnWifi ( complete_callback )
self : toggleWifiOn ( complete_callback , long_press )
end ,
} )
end
@ -349,11 +354,7 @@ function NetworkMgr:getWifiMenuTable()
end
function NetworkMgr : getWifiToggleMenuTable ( )
return {
text = _ ( " Wi-Fi connection " ) ,
enabled_func = function ( ) return Device : hasWifiToggle ( ) end ,
checked_func = function ( ) return NetworkMgr : isWifiOn ( ) end ,
callback = function ( touchmenu_instance )
local toggleCallback = function ( touchmenu_instance , long_press )
local is_wifi_on = NetworkMgr : isWifiOn ( )
local is_connected = NetworkMgr : isConnected ( )
local fully_connected = is_wifi_on and is_connected
@ -397,13 +398,23 @@ function NetworkMgr:getWifiToggleMenuTable()
end
end
if fully_connected then
NetworkMgr : promp tWifiOff( complete_callback )
NetworkMgr : toggle WifiOff( complete_callback )
elseif is_wifi_on and not is_connected then
NetworkMgr : promptWifi ( complete_callback )
-- ask whether user wants to connect or turn off wifi
NetworkMgr : promptWifi ( complete_callback , long_press )
else
NetworkMgr : promp tWifiOn( complete_callback )
NetworkMgr : toggle WifiOn( complete_callback , long_press )
end
end
return {
text = _ ( " Wi-Fi connection " ) ,
enabled_func = function ( ) return Device : hasWifiToggle ( ) end ,
checked_func = function ( ) return NetworkMgr : isWifiOn ( ) end ,
callback = toggleCallback ,
hold_callback = function ( touchmenu_instance )
toggleCallback ( touchmenu_instance , true )
end ,
}
end
@ -580,7 +591,7 @@ function NetworkMgr:getMenuTable(common_settings)
end
end
function NetworkMgr : s howNetworkMenu( complete_callback )
function NetworkMgr : reconnectOrS howNetworkMenu( complete_callback )
local info = InfoMessage : new { text = _ ( " Scanning for networks… " ) }
UIManager : show ( info )
UIManager : nextTick ( function ( )
@ -593,38 +604,30 @@ function NetworkMgr:showNetworkMenu(complete_callback)
-- NOTE: Fairly hackish workaround for #4387,
-- rescan if the first scan appeared to yield an empty list.
--- @fixme This *might* be an issue better handled in lj-wpaclient...
if ( table.getn ( network_list ) == 0 ) then
if # network_list == 0 then
network_list , err = self : getNetworkList ( )
if network_list == nil then
UIManager : show ( InfoMessage : new { text = err } )
return
end
end
-- NOTE: Also supports a disconnect_callback, should we use it for something?
-- Tearing down Wi-Fi completely when tapping "disconnect" would feel a bit harsh, though...
UIManager : show ( require ( " ui/widget/networksetting " ) : new {
network_list = network_list ,
connect_callback = complete_callback ,
} )
end )
end
function NetworkMgr : reconnectOrShowNetworkMenu ( complete_callback )
local info = InfoMessage : new { text = _ ( " Scanning for networks… " ) }
UIManager : show ( info )
UIManager : nextTick ( function ( )
local network_list , err = self : getNetworkList ( )
UIManager : close ( info )
if network_list == nil then
UIManager : show ( InfoMessage : new { text = err } )
return
end
table.sort ( network_list ,
function ( l , r ) return l.signal_quality > r.signal_quality end )
local success = false
if self.wifi_toggle_long_press then
self.wifi_toggle_long_press = nil
else
for dummy , network in ipairs ( network_list ) do
if network.password then
if network.connected then
-- On platforms where we use wpa_supplicant (if we're calling this, we are),
-- the invocation will check its global config, and if an AP configured there is reachable,
-- it'll already have connected to it on its own.
success = true
elseif network.password then
success = NetworkMgr : authenticateNetwork ( network )
end
if success then
NetworkMgr : obtainIP ( )
if complete_callback then
@ -639,6 +642,8 @@ function NetworkMgr:reconnectOrShowNetworkMenu(complete_callback)
end
end
if not success then
-- NOTE: Also supports a disconnect_callback, should we use it for something?
-- Tearing down Wi-Fi completely when tapping "disconnect" would feel a bit harsh, though...
UIManager : show ( require ( " ui/widget/networksetting " ) : new {
network_list = network_list ,
connect_callback = complete_callback ,