2020-01-04 00:18:51 +00:00
local BD = require ( " ui/bidi " )
2014-07-17 13:00:45 +00:00
local ConfirmBox = require ( " ui/widget/confirmbox " )
2016-06-26 00:53:08 +00:00
local DataStorage = require ( " datastorage " )
2014-10-30 18:42:18 +00:00
local Device = require ( " device " )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
local Event = require ( " ui/event " )
2017-04-29 14:30:16 +00:00
local InfoMessage = require ( " ui/widget/infomessage " )
local LuaSettings = require ( " luasettings " )
2021-03-01 00:35:12 +00:00
local MultiConfirmBox = require ( " ui/widget/multiconfirmbox " )
2017-04-29 14:30:16 +00:00
local UIManager = require ( " ui/uimanager " )
2018-01-17 17:16:11 +00:00
local ffiutil = require ( " ffi/util " )
2019-02-08 21:29:11 +00:00
local logger = require ( " logger " )
2014-07-17 13:00:45 +00:00
local _ = require ( " gettext " )
2018-01-17 17:16:11 +00:00
local T = ffiutil.template
2014-08-18 22:48:06 +00:00
2016-06-12 18:50:30 +00:00
local NetworkMgr = { }
2015-02-01 07:16:27 +00:00
2016-09-12 18:49:48 +00:00
function NetworkMgr : readNWSettings ( )
2016-06-26 00:53:08 +00:00
self.nw_settings = LuaSettings : open ( DataStorage : getSettingsDir ( ) .. " /network.lua " )
2016-09-12 18:49:48 +00:00
end
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- Used after restoreWifiAsync() and the turn_on beforeWifiAction to make sure we eventually send a NetworkConnected event,
-- as quite a few things rely on it (KOSync, c.f. #5109; the network activity check, c.f., #6424).
function NetworkMgr : connectivityCheck ( iter , callback , widget )
-- Give up after a while (restoreWifiAsync can take over 45s, so, try to cover that)...
if iter > 25 then
logger.info ( " Failed to restore Wi-Fi (after " , iter , " iterations)! " )
self.wifi_was_on = false
2021-03-06 21:44:18 +00:00
G_reader_settings : makeFalse ( " wifi_was_on " )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- If we abort, murder Wi-Fi and the async script first...
if Device : hasWifiManager ( ) and not Device : isEmulator ( ) then
os.execute ( " pkill -TERM restore-wifi-async.sh 2>/dev/null " )
end
NetworkMgr : turnOffWifi ( )
-- Handle the UI warning if it's from a beforeWifiAction...
if widget then
UIManager : close ( widget )
UIManager : show ( InfoMessage : new { text = _ ( " Error connecting to the network " ) } )
end
2019-07-30 23:00:51 +00:00
return
end
if NetworkMgr : isWifiOn ( ) and NetworkMgr : isConnected ( ) then
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
self.wifi_was_on = true
2021-03-06 21:44:18 +00:00
G_reader_settings : makeTrue ( " wifi_was_on " )
2019-07-30 23:00:51 +00:00
UIManager : broadcastEvent ( Event : new ( " NetworkConnected " ) )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
logger.info ( " Wi-Fi successfully restored (after " , iter , " iterations)! " )
-- Handle the UI & callback if it's from a beforeWifiAction...
if widget then
UIManager : close ( widget )
end
if callback then
callback ( )
else
-- If this trickled down from a turn_onbeforeWifiAction and there is no callback,
-- mention that the action needs to be retried manually.
if widget then
UIManager : show ( InfoMessage : new {
text = _ ( " You can now retry the action that required network access " ) ,
timeout = 3 ,
} )
end
end
2019-07-30 23:00:51 +00:00
else
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
UIManager : scheduleIn ( 2 , function ( ) NetworkMgr : connectivityCheck ( iter + 1 , callback , widget ) end )
2019-07-30 23:00:51 +00:00
end
end
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
function NetworkMgr : scheduleConnectivityCheck ( callback , widget )
UIManager : scheduleIn ( 2 , function ( ) NetworkMgr : connectivityCheck ( 1 , callback , widget ) end )
2019-07-30 23:00:51 +00:00
end
2016-09-12 18:49:48 +00:00
function NetworkMgr : init ( )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- On Kobo, kill Wi-Fi if NetworkMgr:isWifiOn() and NOT NetworkMgr:isConnected()
-- (i.e., if the launcher left the Wi-Fi in an inconsistent state: modules loaded, but no route to gateway).
2019-02-08 21:29:11 +00:00
if Device : isKobo ( ) and self : isWifiOn ( ) and not self : isConnected ( ) then
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
logger.info ( " Kobo Wi-Fi: Left in an inconsistent state by launcher! " )
2019-02-08 21:29:11 +00:00
self : turnOffWifi ( )
end
2016-09-01 07:05:40 +00:00
self.wifi_was_on = G_reader_settings : isTrue ( " wifi_was_on " )
2019-02-08 21:29:11 +00:00
if self.wifi_was_on and G_reader_settings : isTrue ( " auto_restore_wifi " ) then
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- Don't bother if WiFi is already up...
if not ( self : isWifiOn ( ) and self : isConnected ( ) ) then
self : restoreWifiAsync ( )
end
2019-07-30 23:00:51 +00:00
self : scheduleConnectivityCheck ( )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
else
-- Trigger an initial NetworkConnected event if WiFi was already up when we were launched
if NetworkMgr : isWifiOn ( ) and NetworkMgr : isConnected ( ) then
-- NOTE: This needs to be delayed because NetworkListener is initialized slightly later by the FM/Reader app...
UIManager : scheduleIn ( 2 , function ( ) UIManager : broadcastEvent ( Event : new ( " NetworkConnected " ) ) end )
end
2016-09-12 18:49:48 +00:00
end
2016-06-26 00:53:08 +00:00
end
2014-07-17 13:00:45 +00:00
2016-06-26 00:53:08 +00:00
-- Following methods are Device specific which need to be initialized in
-- Device:initNetworkManager. Some of them can be set by calling
-- NetworkMgr:setWirelessBackend
function NetworkMgr : turnOnWifi ( ) end
2016-06-12 18:50:30 +00:00
function NetworkMgr : turnOffWifi ( ) end
2017-10-28 15:51:34 +00:00
function NetworkMgr : isWifiOn ( ) end
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
function NetworkMgr : getNetworkInterfaceName ( ) end
2016-06-26 00:53:08 +00:00
function NetworkMgr : getNetworkList ( ) end
function NetworkMgr : getCurrentNetwork ( ) end
function NetworkMgr : authenticateNetwork ( ) end
function NetworkMgr : disconnectNetwork ( ) end
function NetworkMgr : obtainIP ( ) end
function NetworkMgr : releaseIP ( ) end
2016-09-01 07:05:40 +00:00
-- This function should unblockly call both turnOnWifi() and obtainIP().
function NetworkMgr : restoreWifiAsync ( ) end
2016-06-26 00:53:08 +00:00
-- End of device specific methods
2014-07-17 13:00:45 +00:00
2016-06-26 00:53:08 +00:00
function NetworkMgr : promptWifiOn ( complete_callback )
2014-07-17 13:00:45 +00:00
UIManager : show ( ConfirmBox : new {
2016-03-10 15:26:57 +00:00
text = _ ( " Do you want to turn on Wi-Fi? " ) ,
2017-04-04 13:31:13 +00:00
ok_text = _ ( " Turn on " ) ,
2014-07-17 13:00:45 +00:00
ok_callback = function ( )
2016-09-01 07:05:40 +00:00
self.wifi_was_on = true
2021-03-06 21:44:18 +00:00
G_reader_settings : makeTrue ( " wifi_was_on " )
2016-06-26 00:53:08 +00:00
self : turnOnWifi ( complete_callback )
2014-07-17 13:00:45 +00:00
end ,
} )
end
2016-06-26 00:53:08 +00:00
function NetworkMgr : promptWifiOff ( complete_callback )
2014-07-17 13:00:45 +00:00
UIManager : show ( ConfirmBox : new {
2016-03-10 15:26:57 +00:00
text = _ ( " Do you want to turn off Wi-Fi? " ) ,
2017-04-04 13:31:13 +00:00
ok_text = _ ( " Turn off " ) ,
2014-07-17 13:00:45 +00:00
ok_callback = function ( )
2016-09-01 07:05:40 +00:00
self.wifi_was_on = false
2021-03-06 21:44:18 +00:00
G_reader_settings : makeFalse ( " wifi_was_on " )
2016-06-26 00:53:08 +00:00
self : turnOffWifi ( complete_callback )
2014-07-17 13:00:45 +00:00
end ,
} )
end
2021-03-01 00:35:12 +00:00
function NetworkMgr : promptWifi ( complete_callback )
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
2021-03-06 21:44:18 +00:00
G_reader_settings : makeFalse ( " wifi_was_on " )
2021-03-01 00:35:12 +00:00
self : turnOffWifi ( complete_callback )
end ,
choice2_text = _ ( " Connect " ) ,
choice2_callback = function ( )
self.wifi_was_on = true
2021-03-06 21:44:18 +00:00
G_reader_settings : makeTrue ( " wifi_was_on " )
2021-03-01 00:35:12 +00:00
self : turnOnWifi ( complete_callback )
end ,
} )
end
2018-01-17 17:16:11 +00:00
function NetworkMgr : turnOnWifiAndWaitForConnection ( callback )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
local info = InfoMessage : new { text = _ ( " Connecting to Wi-Fi… " ) }
2018-01-17 17:16:11 +00:00
UIManager : show ( info )
UIManager : forceRePaint ( )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- Don't bother if WiFi is already up...
if not ( self : isWifiOn ( ) and self : isConnected ( ) ) then
self : turnOnWifi ( )
2018-01-17 17:16:11 +00:00
end
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- This will handle sending the proper Event, manage wifi_was_on, as well as tearing down Wi-Fi in case of failures,
-- (i.e., much like getWifiToggleMenuTable).
self : scheduleConnectivityCheck ( callback , info )
end
--- This quirky internal flag is used for the rare beforeWifiAction -> afterWifiAction brackets.
function NetworkMgr : clearBeforeActionFlag ( )
self._before_action_tripped = nil
end
function NetworkMgr : setBeforeActionFlag ( )
self._before_action_tripped = true
end
function NetworkMgr : getBeforeActionFlag ( )
return self._before_action_tripped
2018-01-17 17:16:11 +00:00
end
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
--- @note: The callback will only run *after* a *succesful* network connection.
--- The only guarantee it provides is isConnected (i.e., an IP & a local gateway),
--- *NOT* isOnline (i.e., WAN), se be careful with recursive callbacks!
2018-01-17 17:16:11 +00:00
function NetworkMgr : beforeWifiAction ( callback )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- Remember that we ran, for afterWifiAction...
self : setBeforeActionFlag ( )
2018-01-17 17:16:11 +00:00
local wifi_enable_action = G_reader_settings : readSetting ( " wifi_enable_action " )
if wifi_enable_action == " turn_on " then
NetworkMgr : turnOnWifiAndWaitForConnection ( callback )
else
NetworkMgr : promptWifiOn ( callback )
end
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
end
-- NOTE: This is actually used very sparingly (newsdownloader/send2ebook),
-- because bracketing a single action in a connect/disconnect session doesn't necessarily make much sense...
function NetworkMgr : afterWifiAction ( callback )
-- Don't do anything if beforeWifiAction never actually ran...
if not self : getBeforeActionFlag ( ) then
return
end
self : clearBeforeActionFlag ( )
local wifi_disable_action = G_reader_settings : readSetting ( " wifi_disable_action " )
if wifi_disable_action == " leave_on " then
-- NOP :)
if callback then
callback ( )
end
elseif wifi_disable_action == " turn_off " then
NetworkMgr : turnOffWifi ( callback )
else
NetworkMgr : promptWifiOff ( callback )
end
end
2018-01-17 17:16:11 +00:00
2018-01-17 14:32:54 +00:00
function NetworkMgr : isConnected ( )
2020-06-26 18:47:09 +00:00
if Device : isAndroid ( ) or Device : isCervantes ( ) or Device : isPocketBook ( ) or Device : isEmulator ( ) then
2018-01-17 14:32:54 +00:00
return self : isWifiOn ( )
else
2019-07-30 23:00:51 +00:00
-- Pull the default gateway first, so we don't even try to ping anything if there isn't one...
local default_gw
local std_out = io.popen ( [[/sbin/route -n | awk '$4 == "UG" {print $2}' | tail -n 1]] , " r " )
if std_out then
default_gw = std_out : read ( " *all " )
std_out : close ( )
if not default_gw or default_gw == " " then
return false
end
end
2018-01-17 14:32:54 +00:00
-- `-c1` try only once; `-w2` wait 2 seconds
2019-06-05 19:36:38 +00:00
-- NOTE: No -w flag available in the old busybox build used on Legacy Kindles...
if Device : isKindle ( ) and Device : hasKeyboard ( ) then
2019-07-30 23:00:51 +00:00
return 0 == os.execute ( " ping -c1 " .. default_gw )
2019-06-05 19:36:38 +00:00
else
2019-07-30 23:00:51 +00:00
return 0 == os.execute ( " ping -c1 -w2 " .. default_gw )
2019-06-05 19:36:38 +00:00
end
2018-01-17 14:32:54 +00:00
end
end
2016-11-28 00:40:47 +00:00
function NetworkMgr : isOnline ( )
2015-01-19 16:07:36 +00:00
local socket = require ( " socket " )
2017-08-31 05:02:23 +00:00
-- Microsoft uses `dns.msftncsi.com` for Windows, see
-- <https://technet.microsoft.com/en-us/library/ee126135#BKMK_How> for
-- more information. They also check whether <http://www.msftncsi.com/ncsi.txt>
-- returns `Microsoft NCSI`.
return socket.dns . toip ( " dns.msftncsi.com " ) ~= nil
2014-08-24 12:34:38 +00:00
end
2020-02-07 15:36:17 +00:00
function NetworkMgr : isNetworkInfoAvailable ( )
if Device : isAndroid ( ) then
-- always available
return true
else
--- @todo also show network info when device is authenticated to router but offline
return self : isWifiOn ( )
end
end
2014-11-11 04:12:34 +00:00
function NetworkMgr : setHTTPProxy ( proxy )
local http = require ( " socket.http " )
http.PROXY = proxy
if proxy then
G_reader_settings : saveSetting ( " http_proxy " , proxy )
2021-03-06 21:44:18 +00:00
G_reader_settings : makeTrue ( " http_proxy_enabled " )
2014-11-11 04:12:34 +00:00
else
2021-03-06 21:44:18 +00:00
G_reader_settings : makeFalse ( " http_proxy_enabled " )
2014-11-11 04:12:34 +00:00
end
end
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- Helper functions to hide the quirks of using beforeWifiAction properly ;).
-- Run callback *now* if you're currently online (ie., isOnline),
-- or attempt to go online and run it *ASAP* without any more user interaction.
-- NOTE: If you're currently connected but without Internet access (i.e., isConnected and not isOnline),
-- it will just attempt to re-connect, *without* running the callback.
-- c.f., ReaderWikipedia:onShowWikipediaLookup @ frontend/apps/reader/modules/readerwikipedia.lua
function NetworkMgr : runWhenOnline ( callback )
if self : isOnline ( ) then
callback ( )
else
--- @note: Avoid infinite recursion, beforeWifiAction only guarantees isConnected, not isOnline.
if not self : isConnected ( ) then
self : beforeWifiAction ( callback )
else
self : beforeWifiAction ( )
end
end
end
-- This one is for callbacks that only require isConnected, and since that's guaranteed by beforeWifiAction,
-- you also have a guarantee that the callback *will* run.
function NetworkMgr : runWhenConnected ( callback )
if self : isConnected ( ) then
callback ( )
else
self : beforeWifiAction ( callback )
end
end
-- Mild variants that are used for recursive calls at the beginning of a complex function call.
-- Returns true when not yet online, in which case you should *abort* (i.e., return) the initial call,
-- and otherwise, go-on as planned.
-- NOTE: If you're currently connected but without Internet access (i.e., isConnected and not isOnline),
-- it will just attempt to re-connect, *without* running the callback.
-- c.f., ReaderWikipedia:lookupWikipedia @ frontend/apps/reader/modules/readerwikipedia.lua
function NetworkMgr : willRerunWhenOnline ( callback )
if not self : isOnline ( ) then
--- @note: Avoid infinite recursion, beforeWifiAction only guarantees isConnected, not isOnline.
if not self : isConnected ( ) then
self : beforeWifiAction ( callback )
else
self : beforeWifiAction ( )
end
return true
end
return false
end
-- This one is for callbacks that only require isConnected, and since that's guaranteed by beforeWifiAction,
-- you also have a guarantee that the callback *will* run.
function NetworkMgr : willRerunWhenConnected ( callback )
if not self : isConnected ( ) then
self : beforeWifiAction ( callback )
return true
end
return false
end
2014-11-11 04:12:34 +00:00
function NetworkMgr : getWifiMenuTable ( )
2020-02-07 15:36:17 +00:00
if Device : isAndroid ( ) then
return {
text = _ ( " Wi-Fi settings " ) ,
enabled_func = function ( ) return true end ,
callback = function ( ) NetworkMgr : openSettings ( ) end ,
}
else
return self : getWifiToggleMenuTable ( )
end
end
function NetworkMgr : getWifiToggleMenuTable ( )
2014-11-11 04:12:34 +00:00
return {
2016-03-10 15:26:57 +00:00
text = _ ( " Wi-Fi connection " ) ,
2020-06-26 18:47:09 +00:00
enabled_func = function ( ) return Device : hasWifiToggle ( ) end ,
2018-09-07 23:37:04 +00:00
checked_func = function ( ) return NetworkMgr : isWifiOn ( ) end ,
2018-09-04 21:55:58 +00:00
callback = function ( touchmenu_instance )
2021-03-01 00:35:12 +00:00
local is_wifi_on = NetworkMgr : isWifiOn ( )
local is_connected = NetworkMgr : isConnected ( )
local fully_connected = is_wifi_on and is_connected
2016-06-26 00:53:08 +00:00
local complete_callback = function ( )
2021-03-01 00:35:12 +00:00
-- Notify TouchMenu to update item check state
2018-09-04 21:55:58 +00:00
touchmenu_instance : updateItems ( )
2021-03-01 00:35:12 +00:00
-- If Wi-Fi was on when the menu was shown, this means the tap meant to turn the Wi-Fi *off*,
-- as such, this callback will only be executed *after* the network has been disconnected.
if fully_connected then
2016-10-23 22:27:39 +00:00
UIManager : broadcastEvent ( Event : new ( " NetworkDisconnected " ) )
else
2019-02-20 13:59:33 +00:00
-- On hasWifiManager devices that play with kernel modules directly,
-- double-check that the connection attempt was actually successful...
if Device : isKobo ( ) or Device : isCervantes ( ) then
if NetworkMgr : isWifiOn ( ) and NetworkMgr : isConnected ( ) then
UIManager : broadcastEvent ( Event : new ( " NetworkConnected " ) )
elseif NetworkMgr : isWifiOn ( ) and not NetworkMgr : isConnected ( ) then
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- Don't leave Wi-Fi in an inconsistent state if the connection failed.
2021-03-01 00:35:12 +00:00
-- NOTE: Keep in mind that NetworkSetting only runs this callback on *successful* connections!
-- (It's called connect_callback there).
-- This makes this branch somewhat hard to reach, which is why it gets a dedicated prompt below...
2019-02-20 13:59:33 +00:00
self.wifi_was_on = false
2021-03-06 21:44:18 +00:00
G_reader_settings : makeFalse ( " wifi_was_on " )
2019-02-20 13:59:33 +00:00
-- NOTE: We're limiting this to only a few platforms, as it might be actually harmful on some devices.
-- The intent being to unload kernel modules, and make a subsequent turnOnWifi behave sanely.
-- PB: Relies on netagent, no idea what it does, but it's not using this codepath anyway (!hasWifiToggle)
-- Android: Definitely shouldn't do it.
-- Sony: Doesn't play with modules, don't do it.
-- Kobo: Yes, please.
-- Cervantes: Loads/unloads module, probably could use it like Kobo.
-- Kindle: Probably could use it, if only because leaving Wireless on is generally a terrible idea on Kindle,
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
-- except that we defer to lipc, which makes Wi-Fi handling asynchronous, and the callback is simply delayed by 1s,
-- so we can't be sure the system will actually have finished bringing Wi-Fi up by then...
2019-02-20 13:59:33 +00:00
NetworkMgr : turnOffWifi ( )
touchmenu_instance : updateItems ( )
end
else
-- Assume success on other platforms
UIManager : broadcastEvent ( Event : new ( " NetworkConnected " ) )
end
2016-10-23 22:27:39 +00:00
end
2016-06-26 00:53:08 +00:00
end
2021-03-01 00:35:12 +00:00
if fully_connected then
2016-06-26 00:53:08 +00:00
NetworkMgr : promptWifiOff ( complete_callback )
2021-03-01 00:35:12 +00:00
elseif is_wifi_on and not is_connected then
NetworkMgr : promptWifi ( complete_callback )
2014-11-11 04:12:34 +00:00
else
2016-06-26 00:53:08 +00:00
NetworkMgr : promptWifiOn ( complete_callback )
2014-11-11 04:12:34 +00:00
end
end
}
end
function NetworkMgr : getProxyMenuTable ( )
local proxy_enabled = function ( )
return G_reader_settings : readSetting ( " http_proxy_enabled " )
end
local proxy = function ( )
return G_reader_settings : readSetting ( " http_proxy " )
end
return {
text_func = function ( )
2020-01-04 00:18:51 +00:00
return T ( _ ( " HTTP proxy %1 " ) , ( proxy_enabled ( ) and BD.url ( proxy ( ) ) or " " ) )
2014-11-11 04:12:34 +00:00
end ,
checked_func = function ( ) return proxy_enabled ( ) end ,
callback = function ( )
if not proxy_enabled ( ) and proxy ( ) then
NetworkMgr : setHTTPProxy ( proxy ( ) )
elseif proxy_enabled ( ) then
NetworkMgr : setHTTPProxy ( nil )
end
if not proxy ( ) then
UIManager : show ( InfoMessage : new {
2014-11-28 13:10:37 +00:00
text = _ ( " Tip: \n Long press on this menu entry to configure HTTP proxy. " ) ,
2014-11-11 04:12:34 +00:00
} )
end
end ,
hold_input = {
2014-11-28 13:10:37 +00:00
title = _ ( " Enter proxy address " ) ,
2014-11-11 04:12:34 +00:00
type = " text " ,
hint = proxy ( ) or " " ,
callback = function ( input )
if input ~= " " then
NetworkMgr : setHTTPProxy ( input )
end
end ,
}
}
end
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
function NetworkMgr : getPowersaveMenuTable ( )
return {
2020-07-28 01:53:20 +00:00
text = _ ( " Disable Wi-Fi connection when inactive " ) ,
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
help_text = _ ( [[This will automatically turn Wi-Fi off after a generous period of network inactivity, without disrupting workflows that require a network connection, so you can just keep reading without worrying about battery drain.]] ) ,
checked_func = function ( ) return G_reader_settings : isTrue ( " auto_disable_wifi " ) end ,
enabled_func = function ( ) return Device : hasWifiManager ( ) and not Device : isEmulator ( ) end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " auto_disable_wifi " )
-- NOTE: Well, not exactly, but the activity check wouldn't be (un)scheduled until the next Network(Dis)Connected event...
UIManager : show ( InfoMessage : new {
text = _ ( " This will take effect on next restart. " ) ,
} )
end ,
}
end
2016-09-01 07:05:40 +00:00
function NetworkMgr : getRestoreMenuTable ( )
return {
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
text = _ ( " Restore Wi-Fi connection on resume " ) ,
help_text = _ ( [[This will attempt to automatically and silently re-connect to Wi-Fi on startup or on resume if Wi-Fi used to be enabled the last time you used KOReader.]] ) ,
2019-02-08 21:29:11 +00:00
checked_func = function ( ) return G_reader_settings : isTrue ( " auto_restore_wifi " ) end ,
2019-02-06 14:51:50 +00:00
enabled_func = function ( ) return Device : hasWifiManager ( ) and not Device : isEmulator ( ) end ,
2019-02-08 21:29:11 +00:00
callback = function ( ) G_reader_settings : flipNilOrFalse ( " auto_restore_wifi " ) end ,
2016-09-01 07:05:40 +00:00
}
end
2016-07-27 04:32:13 +00:00
function NetworkMgr : getInfoMenuTable ( )
return {
text = _ ( " Network info " ) ,
2018-09-04 21:55:58 +00:00
keep_menu_open = true ,
2020-02-07 15:36:17 +00:00
enabled_func = function ( ) return self : isNetworkInfoAvailable ( ) end ,
2018-09-04 21:55:58 +00:00
callback = function ( )
2016-07-27 04:32:13 +00:00
if Device.retrieveNetworkInfo then
UIManager : show ( InfoMessage : new {
text = Device : retrieveNetworkInfo ( ) ,
} )
else
UIManager : show ( InfoMessage : new {
2017-04-04 13:31:13 +00:00
text = _ ( " Could not retrieve network info. " ) ,
2016-07-27 04:32:13 +00:00
timeout = 3 ,
} )
end
end
}
end
2018-01-17 17:16:11 +00:00
function NetworkMgr : getBeforeWifiActionMenuTable ( )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
local wifi_enable_action_setting = G_reader_settings : readSetting ( " wifi_enable_action " ) or " prompt "
local wifi_enable_actions = {
turn_on = { _ ( " turn on " ) , _ ( " Turn on " ) } ,
prompt = { _ ( " prompt " ) , _ ( " Prompt " ) } ,
}
local action_table = function ( wifi_enable_action )
return {
text = wifi_enable_actions [ wifi_enable_action ] [ 2 ] ,
checked_func = function ( )
return wifi_enable_action_setting == wifi_enable_action
end ,
callback = function ( )
wifi_enable_action_setting = wifi_enable_action
G_reader_settings : saveSetting ( " wifi_enable_action " , wifi_enable_action )
end ,
}
end
return {
text_func = function ( )
return T ( _ ( " Action when Wi-Fi is off: %1 " ) ,
wifi_enable_actions [ wifi_enable_action_setting ] [ 1 ]
)
end ,
sub_item_table = {
action_table ( " turn_on " ) ,
action_table ( " prompt " ) ,
}
}
end
function NetworkMgr : getAfterWifiActionMenuTable ( )
local wifi_disable_action_setting = G_reader_settings : readSetting ( " wifi_disable_action " ) or " prompt "
local wifi_disable_actions = {
leave_on = { _ ( " leave on " ) , _ ( " Leave on " ) } ,
turn_off = { _ ( " turn off " ) , _ ( " Turn off " ) } ,
prompt = { _ ( " prompt " ) , _ ( " Prompt " ) } ,
}
local action_table = function ( wifi_disable_action )
return {
text = wifi_disable_actions [ wifi_disable_action ] [ 2 ] ,
checked_func = function ( )
return wifi_disable_action_setting == wifi_disable_action
end ,
callback = function ( )
wifi_disable_action_setting = wifi_disable_action
G_reader_settings : saveSetting ( " wifi_disable_action " , wifi_disable_action )
end ,
}
end
return {
text_func = function ( )
return T ( _ ( " Action when done with Wi-Fi: %1 " ) ,
wifi_disable_actions [ wifi_disable_action_setting ] [ 1 ]
)
end ,
sub_item_table = {
action_table ( " leave_on " ) ,
action_table ( " turn_off " ) ,
action_table ( " prompt " ) ,
}
}
2018-01-17 17:16:11 +00:00
end
2018-07-07 15:06:58 +00:00
function NetworkMgr : getDismissScanMenuTable ( )
return {
text = _ ( " Dismiss Wi-Fi scan popup after connection " ) ,
checked_func = function ( ) return G_reader_settings : nilOrTrue ( " auto_dismiss_wifi_scan " ) end ,
2019-02-06 14:51:50 +00:00
enabled_func = function ( ) return Device : hasWifiManager ( ) and not Device : isEmulator ( ) end ,
2018-09-04 21:55:58 +00:00
callback = function ( ) G_reader_settings : flipNilOrTrue ( " auto_dismiss_wifi_scan " ) end ,
2018-07-07 15:06:58 +00:00
}
end
2018-05-13 19:27:52 +00:00
function NetworkMgr : getMenuTable ( common_settings )
2019-02-06 14:51:50 +00:00
if Device : hasWifiToggle ( ) then
common_settings.network_wifi = self : getWifiMenuTable ( )
end
2018-05-13 19:27:52 +00:00
common_settings.network_proxy = self : getProxyMenuTable ( )
common_settings.network_info = self : getInfoMenuTable ( )
2019-02-06 14:51:50 +00:00
if Device : hasWifiManager ( ) then
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
common_settings.network_powersave = self : getPowersaveMenuTable ( )
2019-02-06 14:51:50 +00:00
common_settings.network_restore = self : getRestoreMenuTable ( )
common_settings.network_dismiss_scan = self : getDismissScanMenuTable ( )
common_settings.network_before_wifi_action = self : getBeforeWifiActionMenuTable ( )
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
common_settings.network_after_wifi_action = self : getAfterWifiActionMenuTable ( )
2019-02-06 14:51:50 +00:00
end
2016-09-01 07:05:40 +00:00
end
2016-06-26 00:53:08 +00:00
function NetworkMgr : showNetworkMenu ( complete_callback )
2019-08-24 07:25:38 +00:00
local info = InfoMessage : new { text = _ ( " Scanning for networks… " ) }
2016-06-26 00:53:08 +00:00
UIManager : show ( info )
UIManager : nextTick ( function ( )
2016-10-18 05:02:06 +00:00
local network_list , err = self : getNetworkList ( )
2016-06-26 00:53:08 +00:00
UIManager : close ( info )
2016-10-18 05:02:06 +00:00
if network_list == nil then
UIManager : show ( InfoMessage : new { text = err } )
return
end
2019-01-08 02:56:30 +00:00
-- NOTE: Fairly hackish workaround for #4387,
-- rescan if the first scan appeared to yield an empty list.
2019-08-23 17:53:53 +00:00
--- @fixme This *might* be an issue better handled in lj-wpaclient...
2019-01-08 02:56:30 +00:00
if ( table.getn ( network_list ) == 0 ) then
network_list , err = self : getNetworkList ( )
if network_list == nil then
UIManager : show ( InfoMessage : new { text = err } )
return
end
end
2021-03-01 00:35:12 +00:00
-- 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...
2016-06-26 00:53:08 +00:00
UIManager : show ( require ( " ui/widget/networksetting " ) : new {
network_list = network_list ,
connect_callback = complete_callback ,
} )
end )
end
2019-01-08 15:54:21 +00:00
function NetworkMgr : reconnectOrShowNetworkMenu ( complete_callback )
2019-08-24 07:25:38 +00:00
local info = InfoMessage : new { text = _ ( " Scanning for networks… " ) }
2019-01-08 15:54:21 +00:00
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
2021-01-16 20:44:47 +00:00
for dummy , network in ipairs ( network_list ) do
if network.password then
success = NetworkMgr : authenticateNetwork ( network )
if success then
NetworkMgr : obtainIP ( )
if complete_callback then
complete_callback ( )
end
UIManager : show ( InfoMessage : new {
text = T ( _ ( " Connected to network %1 " ) , BD.wrap ( network.ssid ) ) ,
timeout = 3 ,
} )
break
end
end
end
2019-01-08 15:54:21 +00:00
if not success then
UIManager : show ( require ( " ui/widget/networksetting " ) : new {
network_list = network_list ,
connect_callback = complete_callback ,
} )
end
end )
end
2016-06-26 00:53:08 +00:00
function NetworkMgr : saveNetwork ( setting )
2016-09-12 18:49:48 +00:00
if not self.nw_settings then self : readNWSettings ( ) end
2017-02-27 04:51:04 +00:00
2016-06-26 00:53:08 +00:00
self.nw_settings : saveSetting ( setting.ssid , {
ssid = setting.ssid ,
password = setting.password ,
2017-02-27 04:51:04 +00:00
psk = setting.psk ,
2016-06-26 00:53:08 +00:00
flags = setting.flags ,
} )
self.nw_settings : flush ( )
end
function NetworkMgr : deleteNetwork ( setting )
2016-09-12 18:49:48 +00:00
if not self.nw_settings then self : readNWSettings ( ) end
2016-06-26 00:53:08 +00:00
self.nw_settings : delSetting ( setting.ssid )
self.nw_settings : flush ( )
end
function NetworkMgr : getAllSavedNetworks ( )
2016-09-12 18:49:48 +00:00
if not self.nw_settings then self : readNWSettings ( ) end
2016-06-26 00:53:08 +00:00
return self.nw_settings
end
function NetworkMgr : setWirelessBackend ( name , options )
require ( " ui/network/ " .. name ) . init ( self , options )
end
2014-10-05 08:04:49 +00:00
-- set network proxy if global variable NETWORK_PROXY is defined
if NETWORK_PROXY then
2014-11-11 04:12:34 +00:00
NetworkMgr : setHTTPProxy ( NETWORK_PROXY )
2014-10-05 08:04:49 +00:00
end
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
2016-06-12 18:50:30 +00:00
Device : initNetworkManager ( NetworkMgr )
2016-09-12 18:49:48 +00:00
NetworkMgr : init ( )
2016-06-12 18:50:30 +00:00
2014-07-17 13:00:45 +00:00
return NetworkMgr