Skip to content

Refactor network window - #181

Closed
gmmcosta15 wants to merge 1 commit into
devfrom
ref/network_window
Closed

gmmcosta15 wants to merge 1 commit into
devfrom
ref/network_window

Conversation

@gmmcosta15

@gmmcosta15 gmmcosta15 commented Feb 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Feature
  • Bug fix
  • Code refactor
  • Documentation

This PR delivers a complete refactor of the NetworkManager subsystem and the NetworkControlWindow, replacing the monolithic lib/network.py with a clean
manager/worker architecture. It also incorporates all changes from PR #168 (hotspot QR code) and PR #178 (hotspot config file persistence), which were never
merged to dev.

  • lib/network/manager.py — NetworkManager(QObject): main-thread-safe interface. Submits coroutines to the worker's asyncio loop; emits pyqtSignal for state,
    scan results, connection outcome, connectivity, hotspot config, and errors. Includes a 5-minute keepalive timer as a safety net for missed D-Bus signals.
  • lib/network/worker.py — NetworkManagerWorker: daemon thread owning the asyncio loop and D-Bus connection. Signal-reactive (no polling); 0.8 s debounce for
    rapid NM signal bursts.
  • lib/network/models.py — frozen dataclasses and enums: NetworkInfo, SavedNetwork, NetworkState, ConnectivityState, SecurityType, HotspotConfig, VlanInfo,
    ConnectionPriority, etc.
  • lib/panels/networkWindow.py — NetworkControlWindow rewritten against the manager API: hidden network page, VLAN/DHCP flow, network priority management,
    hotspot QR code, update page.
  • lib/panels/mainWindow.py — wired to the new NetworkManager.
  • lib/qrcode_gen.py — updated to accept hotspot SSID/password/security.
  • configfile.py — added edit_option / get_option helpers for BlocksScreen.cfg (used by hotspot persistence).
  • SVG icons reorganised from btn_icons/ into btn_icons/network/; added ethernet_connected.svg and static_ip.svg; removed internet_cable.svg from the top-bar
    resources.
  • lib/ui/wifiConnectivityWindow.ui and wifiConnectivityWindow_ui.py — deleted (replaced by the new window implementation).
  • list_model.py refactored for the new network list view.
  • pytest.ini — added project-wide pytest configuration (qt_api=pyqt6, asyncio_mode=auto, QT_QPA_PLATFORM=offscreen via tests/conftest.py, integration marker
    gating).
  • scripts/requirements.txt / scripts/requirements-dev.txt — updated dependencies.
  • tests/network/ — unit tests for manager (72 tests, 100 % coverage), worker, models, and a gated sdbus integration test suite; UI tests for
    NetworkControlWindow.
  • tests/util/ — unit tests for list_model and qrcode_gen.

Motivation

The original lib/network.py (≈1 550 lines) mixed D-Bus I/O, Qt signal emission, threading concerns, and business logic in a single file, making it hard to
test, maintain, and extend. The new architecture separates concerns strictly:

  • Testability: the manager and worker can be tested in isolation with mock D-Bus proxies — no real NetworkManager required for unit tests.
  • Thread safety: all D-Bus work runs on the asyncio thread; all Qt widget updates run on the main thread via queued pyqtSignal delivery.
  • Reliability: signal-reactive model (no polling) with debounce; keepalive timer guards against missed D-Bus signals; connection timeout increased to 20 s
    to handle WPA3/Nokia routers.
  • Hotspot persistence (from PR Feat/hotspot qrcode #168 and PR Feature hotspot config file #178): SSID and password survive reboots via BlocksScreen.cfg; QR code displayed on the hotspot panel.

Tests

  • pytest tests/network/ — unit + UI tests, all pass.
  • python -m pytest tests/network/test_manager_unit.py --cov=BlocksScreen.lib.network.manager --cov-report=term-missing — manager.py at 100 %.
  • Integration tests (NM_INTEGRATION_TESTS=1 pytest -m integration tests/network/) require a real NetworkManager and are excluded from CI by default.

Test configuration: pytest.ini, qt_api=pyqt6, asyncio_mode=auto, QT_QPA_PLATFORM=offscreen.

Co-Authors

Co‑author: @Robert0Mart

@gmmcosta15
gmmcosta15 requested a review from HugoCLSC February 27, 2026 11:47
@gmmcosta15 gmmcosta15 self-assigned this Feb 27, 2026
@gmmcosta15
gmmcosta15 marked this pull request as draft February 27, 2026 11:48
@gmmcosta15
gmmcosta15 marked this pull request as ready for review February 27, 2026 11:54
@gmmcosta15 gmmcosta15 changed the title Ref/network window Refactor network window Feb 27, 2026
@gmmcosta15 gmmcosta15 added enhancement New feature or improvement breaking Needs a migration or a coordinated rollout refactor Code change, no behavior change labels Feb 27, 2026
@gmmcosta15
gmmcosta15 marked this pull request as draft February 27, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Needs a migration or a coordinated rollout enhancement New feature or improvement refactor Code change, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant