Skip to content

Commit 61e599e

Browse files
committed
fix(wifi): handle missing WLAN service gracefully
- Don't raise in uninit_wlan() during cleanup when service is unavailable - Handle OSError in get_current_connection() by returning None - Catch init_wlan() failure in scan_available_networks() with proper status - Add SERVICE_UNAVAILABLE scan result status with "Wi-Fi is not available" message
1 parent c0ad4b5 commit 61e599e

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/core/widgets/services/wifi/wifi_managers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class ScanResultStatus(StrEnum):
8282
SUCCESS = "Success"
8383
ACCESS_DENIED = "Access Denied"
8484
POWER_STATE_INVALID = "Power State Invalid"
85+
SERVICE_UNAVAILABLE = "Service Unavailable"
8586
ERROR = "Error"
8687

8788

@@ -323,7 +324,7 @@ def uninit_wlan(self):
323324
None,
324325
)
325326
if result != ERROR_SUCCESS:
326-
raise WinError(result)
327+
logger.debug("Failed to unregister WLAN notification: %s", format_error_message(result))
327328
WlanCloseHandle(self._client_handle, None)
328329
self._client_handle = HANDLE()
329330

@@ -332,7 +333,13 @@ def scan_available_networks(self):
332333
if self._is_scanning:
333334
return
334335
self._is_scanning = True
335-
self.init_wlan()
336+
try:
337+
self.init_wlan()
338+
except OSError as e:
339+
self._is_scanning = False
340+
logger.debug("WLAN service unavailable: %s", e)
341+
self.wifi_scan_completed.emit(ScanResultStatus.SERVICE_UNAVAILABLE, [])
342+
return
336343
# Force a new scan on all interfaces
337344
interfaces_ptr, interfaces = self._get_interface_list()
338345
for interface in interfaces:
@@ -352,7 +359,10 @@ def scan_available_networks(self):
352359

353360
def get_current_connection(self) -> NetworkInfo | None:
354361
"""Get the current WiFi connection"""
355-
self.init_wlan()
362+
try:
363+
self.init_wlan()
364+
except OSError:
365+
return None
356366
interfaces_ptr, interfaces = self._get_interface_list()
357367
network_info: NetworkInfo | None = None
358368
for interface in interfaces:

src/core/widgets/services/wifi/wifi_widgets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,9 @@ def _on_wifi_scan_completed(self, result: ScanResultStatus, networks: list[Netwo
660660
self.error_connection = self.error_message.clicked.connect( # type: ignore[reportUnknownMemberType]
661661
partial(self._run_and_hide, "ms-settings:network-wifi"),
662662
)
663+
elif result == ScanResultStatus.SERVICE_UNAVAILABLE:
664+
self.error_message.clickable = False
665+
self.error_message.setText("Wi-Fi is not available")
663666
elif result == ScanResultStatus.ERROR:
664667
self.error_message.clickable = False
665668
self.error_message.setText("Unknown error...")

0 commit comments

Comments
 (0)