fix conn usage

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

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

Loading…
Cancel
Save