Fix WiFi network selection in TUI prompt (#4566)
* Fix WiFi network selection in TUI prompt TableSelectionScreen returns the selected network in Result._item, but the check on line 136 only tested Result._data (always None for single-select). This caused every selection to fall through to the "No wifi networks found" error path. Fixes #4564 * Fix empty wifi scan crash and simplify network selection Move wifi scanning out of the TableSelectionScreen callback to avoid MenuItemGroup([]) ValueError when no networks are found. The empty result is now handled before the selection screen, and the Selection branch is simplified to a direct get_value() call.
This commit is contained in:
parent
1aff670262
commit
1048f7eef0
|
|
@ -1,4 +1,3 @@
|
||||||
from asyncio import sleep
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import assert_never, override
|
from typing import assert_never, override
|
||||||
|
|
@ -109,36 +108,25 @@ class WifiHandler(InstanceRunnable[bool]):
|
||||||
|
|
||||||
debug(f'Found wifi interface: {wifi_iface}')
|
debug(f'Found wifi interface: {wifi_iface}')
|
||||||
|
|
||||||
async def get_wifi_networks() -> MenuItemGroup:
|
wifi_networks = await self._scan_wifi(wifi_iface)
|
||||||
debug('Scanning Wifi networks')
|
|
||||||
result = self._wpa_cli('scan', wifi_iface)
|
|
||||||
|
|
||||||
if not result.success:
|
if not wifi_networks:
|
||||||
debug(f'Failed to scan wifi networks: {result.error}')
|
debug('No networks found')
|
||||||
return MenuItemGroup([])
|
await NotifyScreen(header=tr('No wifi networks found')).run()
|
||||||
|
tui.exit(Result.false())
|
||||||
|
return False
|
||||||
|
|
||||||
await sleep(5)
|
items = [MenuItem(network.ssid, value=network) for network in wifi_networks]
|
||||||
wifi_networks = self._get_scan_results(wifi_iface)
|
|
||||||
|
|
||||||
items = [MenuItem(network.ssid, value=network) for network in wifi_networks]
|
|
||||||
return MenuItemGroup(items)
|
|
||||||
|
|
||||||
result = await TableSelectionScreen[WifiNetwork](
|
result = await TableSelectionScreen[WifiNetwork](
|
||||||
header=tr('Select wifi network to connect to'),
|
header=tr('Select wifi network to connect to'),
|
||||||
loading_header=tr('Scanning wifi networks...'),
|
group=MenuItemGroup(items),
|
||||||
group_callback=get_wifi_networks,
|
|
||||||
allow_skip=True,
|
allow_skip=True,
|
||||||
allow_reset=True,
|
allow_reset=True,
|
||||||
).run()
|
).run()
|
||||||
|
|
||||||
match result.type_:
|
match result.type_:
|
||||||
case ResultType.Selection:
|
case ResultType.Selection:
|
||||||
if not result.has_data():
|
|
||||||
debug('No networks found')
|
|
||||||
await NotifyScreen(header=tr('No wifi networks found')).run()
|
|
||||||
tui.exit(Result.false())
|
|
||||||
return False
|
|
||||||
|
|
||||||
network = result.get_value()
|
network = result.get_value()
|
||||||
case ResultType.Skip | ResultType.Reset:
|
case ResultType.Skip | ResultType.Reset:
|
||||||
tui.exit(Result.false())
|
tui.exit(Result.false())
|
||||||
|
|
@ -184,6 +172,18 @@ class WifiHandler(InstanceRunnable[bool]):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
async def _scan_wifi(self, wifi_iface: str) -> list[WifiNetwork]:
|
||||||
|
debug('Scanning Wifi networks')
|
||||||
|
scan_result = self._wpa_cli('scan', wifi_iface)
|
||||||
|
|
||||||
|
if not scan_result.success:
|
||||||
|
debug(f'Failed to scan wifi networks: {scan_result.error}')
|
||||||
|
return []
|
||||||
|
|
||||||
|
await LoadingScreen(timer=5, header=tr('Scanning wifi networks...')).run()
|
||||||
|
|
||||||
|
return self._get_scan_results(wifi_iface)
|
||||||
|
|
||||||
async def _notify_failure(self) -> None:
|
async def _notify_failure(self) -> None:
|
||||||
await NotifyScreen(header=tr('Failed setting up wifi')).run()
|
await NotifyScreen(header=tr('Failed setting up wifi')).run()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue