Release Vulpes OS 2.7-preview.24
This commit is contained in:
parent
49572b6b45
commit
97ef99f827
135 changed files with 7717 additions and 2524 deletions
|
|
@ -175,6 +175,39 @@ def active_wifi_uuid():
|
|||
except ValueError:return None
|
||||
|
||||
|
||||
def device_state():
|
||||
"""Return NetworkManager's live link state, even when its AP vanished."""
|
||||
result = nm('-g', 'GENERAL.STATE', 'device', 'show', DEVICE, timeout=5)
|
||||
if result.returncode:
|
||||
raise WifiError('WIFI_UNAVAILABLE')
|
||||
match = re.match(r'\s*(\d+)', result.stdout)
|
||||
if not match:
|
||||
raise WifiError('WIFI_UNAVAILABLE')
|
||||
code = int(match.group(1))
|
||||
state = {20: 'unavailable', 30: 'disconnected', 40: 'connecting',
|
||||
50: 'connecting', 60: 'connecting', 70: 'connecting',
|
||||
80: 'connecting', 90: 'connecting', 100: 'connected',
|
||||
110: 'disconnecting', 120: 'failed'}.get(code, 'unknown')
|
||||
return state
|
||||
|
||||
|
||||
def current_network(profile_dir, observed=()):
|
||||
"""Resolve the active profile to a remembered SSID if scan results omit it."""
|
||||
if device_state() != 'connected':
|
||||
return None
|
||||
uid = active_wifi_uuid()
|
||||
if not uid or uid == HOTSPOT_UUID:
|
||||
return None
|
||||
for network in observed:
|
||||
if network.get('connected'):
|
||||
return network
|
||||
saved = next((row for row in saved_profiles(profile_dir) if row['id'] == uid), None)
|
||||
if not saved:
|
||||
return None
|
||||
return {'ssid': saved['ssid'], 'security': saved['security'],
|
||||
'relSignalStrength': 0, 'savedId': uid, 'connected': True}
|
||||
|
||||
|
||||
def hotspot_state(profile_dir):
|
||||
path=profile_dir/'vulpes-hotspot.nmconnection'
|
||||
result={'enabled':active_wifi_uuid()==HOTSPOT_UUID,'configured':False,'ssid':'Vulpes OS','security':'wpa2-psk','password':''}
|
||||
|
|
@ -269,11 +302,14 @@ def dispatch(request, profile_dir=PROFILE_DIR):
|
|||
for network in found:
|
||||
stored = next((row for row in saved if row['ssid'] == network['ssid'] and row['security'] == network['security']), None)
|
||||
network.update(known=stored is not None, savedId=stored['id'] if stored else None)
|
||||
state = device_state() if enabled else 'disabled'
|
||||
active = current_network(profile_dir, found) if state == 'connected' else None
|
||||
info={}
|
||||
if any(n['connected'] for n in found):
|
||||
if active:
|
||||
try:info=connection_info()
|
||||
except (WifiError,OSError,subprocess.TimeoutExpired):pass
|
||||
return {'enabled': enabled, 'networks': found, 'connectionInformation':info}
|
||||
return {'enabled': enabled, 'state':state, 'network':active,
|
||||
'networks': found, 'connectionInformation':info}
|
||||
if operation == 'disconnect':
|
||||
if nm('device', 'disconnect', DEVICE).returncode:
|
||||
raise WifiError('WIFI_DISCONNECT_FAILED')
|
||||
|
|
@ -304,7 +340,10 @@ def dispatch(request, profile_dir=PROFILE_DIR):
|
|||
private_write(target, text)
|
||||
if nm('connection', 'load', str(target)).returncode:
|
||||
raise WifiError('WIFI_UNAVAILABLE')
|
||||
if nm('connection', 'up', 'uuid', uid).returncode:
|
||||
# NetworkManager may retain a failed activation after the AP goes out
|
||||
# of range. Explicitly drop that stale activation before reconnecting.
|
||||
nm('connection', 'down', 'uuid', uid)
|
||||
if nm('connection', 'up', 'uuid', uid, 'ifname', DEVICE).returncode:
|
||||
raise WifiError('WIFI_CONNECT_FAILED')
|
||||
connected = True
|
||||
return {'connected': True}
|
||||
|
|
|
|||
Loading…
Reference in a new issue