From 8968acd64401f4edd07bdd9aedf6feb4fab198ef Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Fri, 10 May 2024 19:38:27 +0400 Subject: [PATCH] feat(vscode): show a notification with chime and led feedback when VSCode successfully logs in #96 --- CHANGELOG.md | 2 ++ ubo_app/services/050-vscode/reducer.py | 44 ++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 329cd783..3ad27be3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ in the service file so that user can easily add their custom services - fix(voice): remove "clear access key" item when access key is not set #97 - refactor(vscode): flatten vscode menu items into its main menu #102 +- feat(vscode): show a notification with chime and led feedback when VSCode successfully + logs in #96 ## Version 0.14.0 diff --git a/ubo_app/services/050-vscode/reducer.py b/ubo_app/services/050-vscode/reducer.py index 55959946..683b6a8a 100644 --- a/ubo_app/services/050-vscode/reducer.py +++ b/ubo_app/services/050-vscode/reducer.py @@ -3,8 +3,20 @@ from dataclasses import replace -from redux import InitAction, InitializationActionError +from redux import ( + BaseEvent, + CompleteReducerResult, + InitAction, + InitializationActionError, +) +from ubo_gui.constants import SUCCESS_COLOR +from ubo_app.store.services.notifications import ( + Importance, + Notification, + NotificationDisplayType, + NotificationsAddAction, +) from ubo_app.store.services.vscode import ( VSCodeAction, VSCodeDoneDownloadingAction, @@ -14,7 +26,12 @@ ) -def reducer(state: VSCodeState | None, action: VSCodeAction) -> VSCodeState: +def reducer( + state: VSCodeState | None, + action: VSCodeAction, +) -> ( + CompleteReducerResult[VSCodeState, NotificationsAddAction, BaseEvent] | VSCodeState +): if state is None: if isinstance(action, InitAction): return VSCodeState() @@ -27,11 +44,32 @@ def reducer(state: VSCodeState | None, action: VSCodeAction) -> VSCodeState: return replace(state, is_downloading=False) if isinstance(action, VSCodeSetStatusAction): - return replace( + actions = [] + if ( + (not state.status or not state.status.is_running) + and action.status + and action.status.is_running + ): + actions.append( + NotificationsAddAction( + notification=Notification( + title='VSCode', + content='Service is running', + icon='󰨞', + importance=Importance.MEDIUM, + color=SUCCESS_COLOR, + display_type=NotificationDisplayType.FLASH, + ), + ), + ) + + state = replace( state, is_binary_installed=action.is_binary_installed, is_logged_in=action.is_logged_in, status=action.status, ) + return CompleteReducerResult(state=state, actions=actions) + return state