From 94b9d82f49eafe3a7713af6a3c8b4022c89bcf57 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Tue, 20 Aug 2024 10:44:35 +0400 Subject: [PATCH] fix(wifi): improve the logic of wifi onboarding notification --- CHANGELOG.md | 4 + pyproject.toml | 2 +- .../wireless_flow/store-rpi-000.jsonc | 2 +- .../wireless_flow/store-rpi-001.jsonc | 2 +- .../wireless_flow/store-rpi-002.jsonc | 2 +- .../wireless_flow/store-rpi-003.jsonc | 2 +- .../wireless_flow/store-rpi-004.jsonc | 2 +- .../wireless_flow/store-rpi-005.jsonc | 2 +- .../store-desktop-000.jsonc | 2 +- .../all_services_register/store-rpi-000.jsonc | 2 +- ubo_app/services/030-wifi/setup.py | 86 +++++++++++-------- 11 files changed, 61 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3676e6db..dc31ae10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Version 0.15.8 + +- fix(wifi): improve the logic of wifi onboarding notification + ## Version 0.15.7 - refactor(core): general housekeeping, improve resource management in runtime and test environment, minor bug fixes diff --git a/pyproject.toml b/pyproject.toml index 7e9c4762..6c5f9fee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ubo-app" -version = "0.15.7" +version = "0.15.8" description = "Ubo main app, running on device initialization. A platform for running other apps." authors = ["Sassan Haradji "] license = "Apache-2.0" diff --git a/tests/flows/results/test_wireless/wireless_flow/store-rpi-000.jsonc b/tests/flows/results/test_wireless/wireless_flow/store-rpi-000.jsonc index 8109eb96..55407284 100644 --- a/tests/flows/results/test_wireless/wireless_flow/store-rpi-000.jsonc +++ b/tests/flows/results/test_wireless/wireless_flow/store-rpi-000.jsonc @@ -2,6 +2,6 @@ { "connections": [], "current_connection": null, - "has_visited_onboarding": true, + "has_visited_onboarding": null, "state": "Disconnected" } diff --git a/tests/flows/results/test_wireless/wireless_flow/store-rpi-001.jsonc b/tests/flows/results/test_wireless/wireless_flow/store-rpi-001.jsonc index 38802034..70da44d1 100644 --- a/tests/flows/results/test_wireless/wireless_flow/store-rpi-001.jsonc +++ b/tests/flows/results/test_wireless/wireless_flow/store-rpi-001.jsonc @@ -18,6 +18,6 @@ "state": "Connected", "type": null }, - "has_visited_onboarding": true, + "has_visited_onboarding": null, "state": "Connected" } diff --git a/tests/flows/results/test_wireless/wireless_flow/store-rpi-002.jsonc b/tests/flows/results/test_wireless/wireless_flow/store-rpi-002.jsonc index 1cdcc261..3f2d08c7 100644 --- a/tests/flows/results/test_wireless/wireless_flow/store-rpi-002.jsonc +++ b/tests/flows/results/test_wireless/wireless_flow/store-rpi-002.jsonc @@ -11,6 +11,6 @@ } ], "current_connection": null, - "has_visited_onboarding": true, + "has_visited_onboarding": null, "state": "Disconnected" } diff --git a/tests/flows/results/test_wireless/wireless_flow/store-rpi-003.jsonc b/tests/flows/results/test_wireless/wireless_flow/store-rpi-003.jsonc index 8be2feb9..72283089 100644 --- a/tests/flows/results/test_wireless/wireless_flow/store-rpi-003.jsonc +++ b/tests/flows/results/test_wireless/wireless_flow/store-rpi-003.jsonc @@ -18,6 +18,6 @@ "state": "Connected", "type": null }, - "has_visited_onboarding": true, + "has_visited_onboarding": null, "state": "Connected" } diff --git a/tests/flows/results/test_wireless/wireless_flow/store-rpi-004.jsonc b/tests/flows/results/test_wireless/wireless_flow/store-rpi-004.jsonc index f4e63b12..e2ed73e0 100644 --- a/tests/flows/results/test_wireless/wireless_flow/store-rpi-004.jsonc +++ b/tests/flows/results/test_wireless/wireless_flow/store-rpi-004.jsonc @@ -2,6 +2,6 @@ { "connections": [], "current_connection": null, - "has_visited_onboarding": true, + "has_visited_onboarding": null, "state": "Disconnected" } diff --git a/tests/flows/results/test_wireless/wireless_flow/store-rpi-005.jsonc b/tests/flows/results/test_wireless/wireless_flow/store-rpi-005.jsonc index cde603a3..81db642f 100644 --- a/tests/flows/results/test_wireless/wireless_flow/store-rpi-005.jsonc +++ b/tests/flows/results/test_wireless/wireless_flow/store-rpi-005.jsonc @@ -2,6 +2,6 @@ { "connections": [], "current_connection": null, - "has_visited_onboarding": true, + "has_visited_onboarding": null, "state": "Disconnected" } diff --git a/tests/integration/results/test_services/all_services_register/store-desktop-000.jsonc b/tests/integration/results/test_services/all_services_register/store-desktop-000.jsonc index 0e4b8bac..530a7e40 100644 --- a/tests/integration/results/test_services/all_services_register/store-desktop-000.jsonc +++ b/tests/integration/results/test_services/all_services_register/store-desktop-000.jsonc @@ -774,7 +774,7 @@ } ], "current_connection": null, - "has_visited_onboarding": true, + "has_visited_onboarding": null, "state": "Disconnected" } } diff --git a/tests/integration/results/test_services/all_services_register/store-rpi-000.jsonc b/tests/integration/results/test_services/all_services_register/store-rpi-000.jsonc index f3fa03a5..9d3a5156 100644 --- a/tests/integration/results/test_services/all_services_register/store-rpi-000.jsonc +++ b/tests/integration/results/test_services/all_services_register/store-rpi-000.jsonc @@ -765,7 +765,7 @@ "wifi": { "connections": [], "current_connection": null, - "has_visited_onboarding": true, + "has_visited_onboarding": null, "state": "Disconnected" } } diff --git a/ubo_app/services/030-wifi/setup.py b/ubo_app/services/030-wifi/setup.py index 17c4e9da..9ea07fe7 100644 --- a/ubo_app/services/030-wifi/setup.py +++ b/ubo_app/services/030-wifi/setup.py @@ -3,6 +3,7 @@ from debouncer import DebounceOptions, debounce from pages import create_wireless_connection, main +from redux import AutorunOptions from ubo_gui.constants import INFO_COLOR from wifi_manager import ( get_connections, @@ -16,7 +17,7 @@ RegisterSettingAppAction, SettingsCategory, ) -from ubo_app.store.main import dispatch, subscribe_event +from ubo_app.store.main import autorun, dispatch, subscribe_event from ubo_app.store.services.notifications import ( Importance, Notification, @@ -70,39 +71,40 @@ async def setup_listeners() -> None: create_task(update_wifi_list()) +ONBOARDING_NOTIFICATION = Notification( + title='No internet connection', + content='Press middle button "󱚾" to add WiFi network', + importance=Importance.MEDIUM, + icon='󱚵', + display_type=NotificationDisplayType.STICKY, + actions=[ + NotificationActionItem( + action=lambda: (create_wireless_connection.CreateWirelessConnectionPage), + icon='󱚾', + background_color=INFO_COLOR, + dismiss_notification=True, + ), + ], + extra_information=NotificationExtraInformation( + text='Press middle button to add WiFi network with QR code.\n' + 'If you dismiss this, you can always add WiFi network through ' + 'Settings → Network → WiFi', + piper_text='Press middle button to add WiFi network with QR code.\n' + 'If you dismiss this, you can always add WiFi network through ' + 'Settings menu, by navigating to Network, and then WiFi', + picovoice_text='Press middle button to add {WiFi|W AY F AY} ' + 'network with {QR|K Y UW AA R} code.\n' + 'If you dismiss this, you can always add {WiFi|W AY F AY} network ' + 'through Settings → Network → {WiFi|W AY F AY}', + ), + color=INFO_COLOR, +) + + def show_onboarding_notification() -> None: dispatch( NotificationsAddAction( - notification=Notification( - title='No internet connection', - content='Press middle button "󱚾" to add WiFi network', - importance=Importance.MEDIUM, - icon='󱚵', - display_type=NotificationDisplayType.STICKY, - actions=[ - NotificationActionItem( - action=lambda: ( - create_wireless_connection.CreateWirelessConnectionPage - ), - icon='󱚾', - background_color=INFO_COLOR, - dismiss_notification=True, - ), - ], - extra_information=NotificationExtraInformation( - text='Press middle button to add WiFi network with QR code.\n' - 'If you dismiss this, you can always add WiFi network through ' - 'Settings → Network → WiFi', - piper_text='Press middle button to add WiFi network with QR code.\n' - 'If you dismiss this, you can always add WiFi network through ' - 'Settings menu, by navigating to Network, and then WiFi', - picovoice_text='Press middle button to add {WiFi|W AY F AY} ' - 'network with {QR|K Y UW AA R} code.\n' - 'If you dismiss this, you can always add {WiFi|W AY F AY} network ' - 'through Settings → Network → {WiFi|W AY F AY}', - ), - color=INFO_COLOR, - ), + notification=ONBOARDING_NOTIFICATION, ), ) @@ -126,10 +128,18 @@ async def init_service() -> None: subscribe_event(WiFiUpdateRequestEvent, request_scan) - if not read_from_persistent_store( - key='wifi_has_visited_onboarding', - default=False, - ): - logger.info('No internet connection, showing WiFi onboarding.') - show_onboarding_notification() - dispatch(WiFiSetHasVisitedOnboardingAction(has_visited_onboarding=True)) + @autorun( + lambda state: state.ip.is_connected, + options=AutorunOptions(default_value=None), + ) + def check_onboarding(is_connected: bool | None) -> None: + if is_connected is False and not read_from_persistent_store( + key='wifi_has_visited_onboarding', + default=False, + ): + logger.info('No internet connection, showing WiFi onboarding.') + show_onboarding_notification() + dispatch(WiFiSetHasVisitedOnboardingAction(has_visited_onboarding=True)) + + if is_connected is not None: + check_onboarding.unsubscribe()