util.connection_available(): Prefer 'ip' to 'ifconfig'

Closes #974.
This commit is contained in:
Teemu Ikonen 2021-03-09 20:56:58 +02:00
parent e2bd98c346
commit a60183e49c
1 changed files with 7 additions and 14 deletions

View File

@ -1881,25 +1881,18 @@ def connection_available():
elif gpodder.ui.osx:
return len(list(osx_get_active_interfaces())) > 0
else:
# By default, we assume we're not offline (bug 1730)
offline = False
# By default, we assume we're online (bug 1730)
online = True
if find_command('ifconfig') is not None:
if find_command('ip') is not None:
online = bool(list(linux_get_active_interfaces()))
elif find_command('ifconfig') is not None:
# If ifconfig is available, and it says we don't have
# any active interfaces, assume we're offline
if len(list(unix_get_active_interfaces())) == 0:
offline = True
online = bool(list(unix_get_active_interfaces()))
# If we assume we're offline, try the "ip" command as fallback
if offline and find_command('ip') is not None:
if len(list(linux_get_active_interfaces())) == 0:
offline = True
else:
offline = False
return online
return not offline
return False
except Exception as e:
logger.warn('Cannot get connection status: %s', e, exc_info=True)
# When we can't determine the connection status, act as if we're online (bug 1730)