Skip to content

Commit

Permalink
fix(core): avoid side-effects after FinishEvent is dispatched.
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Aug 22, 2024
1 parent 0cb15c1 commit 04bc7c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- build(packer): set `autologin-user` to `ubo` in `/etc/lightdm/lightdm.conf`
- feat(core): improve update notification for phase-2 of the update process and add a spinner on top-left
- fix(core): avoid side-effects after `FinishEvent` is dispatched.

## Version 0.15.8

Expand Down
12 changes: 10 additions & 2 deletions ubo_app/store/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from asyncio import Handle
from datetime import datetime
from pathlib import Path
from threading import current_thread, main_thread
from threading import Event, current_thread, main_thread
from types import GenericAlias
from typing import TYPE_CHECKING, Any, TypeVar, cast, get_origin, overload

Expand All @@ -20,6 +20,7 @@
CombineReducerAction,
CreateStoreOptions,
FinishAction,
FinishEvent,
InitAction,
Store,
combine_reducers,
Expand Down Expand Up @@ -259,7 +260,9 @@ def action_middleware(action: ActionType) -> ActionType:
return action


def event_middleware(event: EventType) -> EventType:
def event_middleware(event: EventType) -> EventType | None:
if is_finalizing.is_set():
return None
logger.debug(
'Event dispatched',
extra={'event': event},
Expand All @@ -286,6 +289,11 @@ def event_middleware(event: EventType) -> EventType:
subscribe_event = store.subscribe_event
view = store.view


is_finalizing = Event()

subscribe_event(FinishEvent, lambda: is_finalizing.set())

dispatch(InitAction())

if DEBUG_MODE:
Expand Down

0 comments on commit 04bc7c9

Please sign in to comment.