Skip to content

Commit

Permalink
fix(wifi): improve the logic of wifi onboarding notification
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Aug 20, 2024
1 parent 3af322b commit 94b9d82
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "Apache-2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
"connections": [],
"current_connection": null,
"has_visited_onboarding": true,
"has_visited_onboarding": null,
"state": "Disconnected"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"state": "Connected",
"type": null
},
"has_visited_onboarding": true,
"has_visited_onboarding": null,
"state": "Connected"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
}
],
"current_connection": null,
"has_visited_onboarding": true,
"has_visited_onboarding": null,
"state": "Disconnected"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"state": "Connected",
"type": null
},
"has_visited_onboarding": true,
"has_visited_onboarding": null,
"state": "Connected"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
"connections": [],
"current_connection": null,
"has_visited_onboarding": true,
"has_visited_onboarding": null,
"state": "Disconnected"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
"connections": [],
"current_connection": null,
"has_visited_onboarding": true,
"has_visited_onboarding": null,
"state": "Disconnected"
}
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@
}
],
"current_connection": null,
"has_visited_onboarding": true,
"has_visited_onboarding": null,
"state": "Disconnected"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@
"wifi": {
"connections": [],
"current_connection": null,
"has_visited_onboarding": true,
"has_visited_onboarding": null,
"state": "Disconnected"
}
}
86 changes: 48 additions & 38 deletions ubo_app/services/030-wifi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
),
)

Expand All @@ -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()

0 comments on commit 94b9d82

Please sign in to comment.