From 865851c1c1f8a29d66df4b6d088fd7ab9d480a9f Mon Sep 17 00:00:00 2001 From: Greg Kopp Date: Sun, 6 Jul 2025 00:05:35 -0400 Subject: [PATCH] Check for nmcli --- rcp/components/setup/network_screen.py | 34 +++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/rcp/components/setup/network_screen.py b/rcp/components/setup/network_screen.py index b97c8cd..ce208cb 100644 --- a/rcp/components/setup/network_screen.py +++ b/rcp/components/setup/network_screen.py @@ -43,7 +43,11 @@ class NetworkScreen(Screen): def __init__(self, **kv): super().__init__(**kv) self.ids['grid_layout'].bind(minimum_height=self.ids['grid_layout'].setter('height')) - self.wifi_enabled = nmcli.radio().wifi + try: + self.wifi_enabled = nmcli.radio().wifi + except FileNotFoundError: + log.warning("nmcli not found, network features will be disabled.") + self.wifi_enabled = False Clock.schedule_once(lambda dt: asyncio.ensure_future(self.refresh())) self.status_update_task = Clock.schedule_interval(lambda dt: asyncio.ensure_future(self.status_update()), timeout=1) @@ -53,6 +57,8 @@ def log(self, message: str): self.status_text += f"{message}\n" async def status_update(self): + if not self.wifi_enabled: + return if self.device != "": data = await asyncio.to_thread(nmcli.device.show, self.device) new_state = data.get("GENERAL.STATE") @@ -61,6 +67,9 @@ async def status_update(self): await self.refresh() async def refresh(self): + if not self.wifi_enabled: + self.log("nmcli not available, network features disabled") + return log.debug("Refresh properties invoked") # Scan Devices @@ -103,6 +112,9 @@ async def refresh(self): self.lock = False async def connect(self): + if not self.wifi_enabled: + self.log("nmcli not available, network features disabled") + return self.log("Request Wifi Connection") connections_dict = await asyncio.to_thread(nmcli.connection) @@ -134,14 +146,18 @@ async def connect(self): self.log(f"Unable to connect: {e.__str__()}") def on_wifi_enabled(self, instance, value): - if self.wifi_enabled: - self.log("Enable Wifi Connections") - nmcli.radio.wifi_on() - self.log("Run Scan to find the available access points") - else: - self.log("Disable Wifi Connections") - nmcli.radio.wifi_off() - + try: + if self.wifi_enabled: + self.log("Enable Wifi Connections") + nmcli.radio.wifi_on() + self.log("Run Scan to find the available access points") + else: + self.log("Disable Wifi Connections") + nmcli.radio.wifi_off() + except FileNotFoundError: + log.warning("nmcli not found, network features will be disabled.") + self.wifi_enabled = False + def apply(self): self.lock = True Clock.schedule_once(lambda dt: asyncio.ensure_future(self.connect()))