fix conn usage

pull/36039/head
Shane Smiskol 2 days ago
parent 2f0a44511d
commit e026359931
  1. 91
      system/ui/lib/wifi_manager.py

@ -247,8 +247,6 @@ class WifiManager:
def _monitor_state(self):
device_path: str = self._wait_for_wifi_device()
conn = open_dbus_connection(bus="SYSTEM")
rule = MatchRule(
type="signal",
interface=NM_DEVICE_IFACE,
@ -257,50 +255,51 @@ class WifiManager:
)
# Filter for StateChanged signal
conn.send_and_get_reply(message_bus.AddMatch(rule))
try:
with conn.filter(rule, queue=deque(maxlen=10)) as q: # TODO: not sure what to choose for this
while not self._exit:
# TODO: now that we have a nice poller we can run always?
# TODO: actually nah since it affects UI currently? or not?
if not self._active:
time.sleep(1)
continue
# Block until a matching signal arrives
try:
msg = conn.recv_until_filtered(q, timeout=1)
except TimeoutError:
continue
print('msg.body', msg.body)
new_state, previous_state, change_reason = msg.body
print(f"------------ WiFi device state change: {new_state}, change reason: {change_reason}")
# BAD PASSWORD
if new_state == NMDeviceState.NEED_AUTH and change_reason == NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT and len(self._connecting_to_ssid):
print('------ NEED AUTH - SUPPLICANT DISCONNECT')
# TODO: this didn't show wrong password dialog but we were here
self.forget_connection(self._connecting_to_ssid, block=True)
if self._need_auth is not None:
self._need_auth(self._connecting_to_ssid)
self._connecting_to_ssid = ""
elif new_state == NMDeviceState.ACTIVATED:
print('------ ACTIVATED')
if self._activated is not None:
self._update_networks()
print('CALLING ACTIVATED CALLBACK1')
self._activated()
self._connecting_to_ssid = ""
elif new_state == NMDeviceState.DISCONNECTED and change_reason != NM_DEVICE_STATE_REASON_NEW_ACTIVATION:
print('------ DISCONNECTED')
self._connecting_to_ssid = ""
if self._disconnected is not None:
self._disconnected()
finally:
conn.close()
self._conn_monitor.send_and_get_reply(message_bus.AddMatch(rule))
with self._conn_monitor.filter(rule, queue=deque(maxlen=10)) as q: # TODO: not sure what to choose for this
while not self._exit:
# TODO: now that we have a nice poller we can run always?
# TODO: actually nah since it affects UI currently? or not?
if not self._active:
time.sleep(1)
continue
# Block until a matching signal arrives
try:
msg = self._conn_monitor.recv_until_filtered(q, timeout=1)
except TimeoutError:
continue
print('msg.body', msg.body)
new_state, previous_state, change_reason = msg.body
print(f"------------ WiFi device state change: {new_state}, change reason: {change_reason}")
# BAD PASSWORD
if new_state == NMDeviceState.NEED_AUTH and change_reason == NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT and len(self._connecting_to_ssid):
print('------ NEED AUTH - SUPPLICANT DISCONNECT')
# TODO: this didn't show wrong password dialog but we were here
print('forgetting connection to', self._connecting_to_ssid)
self.forget_connection(self._connecting_to_ssid, block=True)
print('forgot successful')
print('need auth is none?', self._need_auth is None)
if self._need_auth is not None:
print('CALLING NEED AUTH CALLBACK')
self._need_auth(self._connecting_to_ssid)
print('done calling')
self._connecting_to_ssid = ""
elif new_state == NMDeviceState.ACTIVATED:
print('------ ACTIVATED')
if self._activated is not None:
self._update_networks()
print('CALLING ACTIVATED CALLBACK1')
self._activated()
self._connecting_to_ssid = ""
elif new_state == NMDeviceState.DISCONNECTED and change_reason != NM_DEVICE_STATE_REASON_NEW_ACTIVATION:
print('------ DISCONNECTED')
self._connecting_to_ssid = ""
if self._disconnected is not None:
self._disconnected()
def _network_scanner(self):
self._wait_for_wifi_device()

Loading…
Cancel
Save