diff --git a/system/ui/lib/wifi_manager.py b/system/ui/lib/wifi_manager.py index 64621a8afb..4479ec5950 100644 --- a/system/ui/lib/wifi_manager.py +++ b/system/ui/lib/wifi_manager.py @@ -52,6 +52,13 @@ def get_security_type(flags: int, wpa_flags: int, rsn_flags: int) -> SecurityTyp return SecurityType.UNSUPPORTED +def run_blocking(func: Callable, block: bool): + if block: + func() + else: + threading.Thread(target=func, daemon=True).start() + + @dataclass(frozen=True) class Network: ssid: str @@ -319,11 +326,7 @@ class WifiManager: if self._forgotten is not None: self._forgotten(ssid) - # TODO: make a helper when it makes sense - if block: - worker() - else: - threading.Thread(target=worker, daemon=True).start() + run_blocking(worker, block) def activate_connection(self, ssid: str, block: bool = False): def worker(): @@ -342,11 +345,7 @@ class WifiManager: # if self._activated is not None: # self._activated() - # TODO: make a helper when it makes sense - if block: - worker() - else: - threading.Thread(target=worker, daemon=True).start() + run_blocking(worker, block) def _request_scan(self): if self._wifi_device is None: