From 234b635965712e3ec80627abca5e9d4b05730cc3 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 22 Aug 2025 21:08:39 -0700 Subject: [PATCH] hide/show event no lag hopefully yayay --- selfdrive/ui/layouts/settings/settings.py | 6 +++-- system/ui/lib/wifi_manager_v2.py | 28 +++++++++++++++++++++-- system/ui/widgets/__init__.py | 6 +++++ system/ui/widgets/network.py | 9 ++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/layouts/settings/settings.py b/selfdrive/ui/layouts/settings/settings.py index 41c5032ec7..372185f860 100644 --- a/selfdrive/ui/layouts/settings/settings.py +++ b/selfdrive/ui/layouts/settings/settings.py @@ -58,9 +58,9 @@ class SettingsLayout(Widget): # self.wifi_manager = WifiManagerWrapper() self.wifi_manager = WifiManager() + self.wifi_manager.set_active(False) self.wifi_ui = WifiManagerUI(self.wifi_manager) - self._panels = { PanelType.DEVICE: PanelInfo("Device", DeviceLayout()), PanelType.NETWORK: PanelInfo("Network", self.wifi_ui), @@ -76,7 +76,7 @@ class SettingsLayout(Widget): self._close_callback: Callable | None = None # def __del__(self): - # self.wifi_manager.shutdown() + # self.wifi_manager.stop() def set_callbacks(self, on_close: Callable): self._close_callback = on_close @@ -162,7 +162,9 @@ class SettingsLayout(Widget): def set_current_panel(self, panel_type: PanelType): if panel_type != self._current_panel: + self._panels[self._current_panel].instance.hide_event() self._current_panel = panel_type + self._panels[self._current_panel].instance.show_event() def close_settings(self): if self._close_callback: diff --git a/system/ui/lib/wifi_manager_v2.py b/system/ui/lib/wifi_manager_v2.py index 32b067596e..5d3993e485 100644 --- a/system/ui/lib/wifi_manager_v2.py +++ b/system/ui/lib/wifi_manager_v2.py @@ -154,6 +154,7 @@ class WifiManager: while self._running: if self._active: + print('moritring state ACTivE!!1') dev_state = int(props_dev.Get(NM_DEVICE_IFACE, "State")) state_reason = props_dev.Get(NM_DEVICE_IFACE, "StateReason") # (u state, u reason) reason = int(state_reason[1]) if isinstance(state_reason, (list, tuple)) and len(state_reason) == 2 else 0 @@ -198,11 +199,17 @@ class WifiManager: self._disconnected = disconnected def _run(self): + i = 0 while self._running: if self._active: - self._update_networks() + print('we;re acti!!!!!!!!!!!!') + # Scan for networks every 5 seconds + if i % 5 == 0: + self._update_networks() + self._request_scan() - time.sleep(3) + i += 1 + time.sleep(1) def set_active(self, active: bool): self._active = active @@ -323,6 +330,23 @@ class WifiManager: # if self._activated is not None: # self._activated() + def _request_scan(self): + device_path = self._get_wifi_device() + if device_path is None: + cloudlog.warning("No WiFi device found") + return + + wifi_iface = dbus.Interface(self._bus.get_object(NM, device_path), NM_WIRELESS_IFACE) + try: + wifi_iface.RequestScan({}) + print('Requested scan') + except dbus.exceptions.DBusException as e: + # TODO: copilot is wrong, this never happens + if "org.freedesktop.NetworkManager.Device.Error.AlreadyScanning" in str(e): + print('Already scanning, skipping') + else: + cloudlog.exception("Failed to request scan") + def _update_networks(self): # TODO: only run this function on scan complete! print('UPDATING NETWORKS!!!!') diff --git a/system/ui/widgets/__init__.py b/system/ui/widgets/__init__.py index d45f48ac38..3dd7cd3fe3 100644 --- a/system/ui/widgets/__init__.py +++ b/system/ui/widgets/__init__.py @@ -129,3 +129,9 @@ class Widget(abc.ABC): def _handle_mouse_release(self, mouse_pos: MousePos) -> bool: """Optionally handle mouse release events.""" return False + + def show_event(self): + """Optionally handle show event. Parent must manually call this""" + + def hide_event(self): + """Optionally handle hide event. Parent must manually call this""" diff --git a/system/ui/widgets/network.py b/system/ui/widgets/network.py index f65ae91086..4b06296daf 100644 --- a/system/ui/widgets/network.py +++ b/system/ui/widgets/network.py @@ -82,6 +82,15 @@ class WifiManagerUI(Widget): networks_updated=self._on_network_updated, disconnected=self._on_disconnected) + def show_event(self): + print('networking widget shown, stasrting wifisz scaing') + # start/stop scanning when widget is visible + self.wifi_manager.set_active(True) + + def hide_event(self): + print('networkign widet hidden, stopping wifisz') + self.wifi_manager.set_active(False) + def _render(self, rect: rl.Rectangle): with self._lock: if not self._networks: