diff options
| author | AAGaming <aagaming@riseup.net> | 2023-12-31 20:29:19 -0500 |
|---|---|---|
| committer | AAGaming <aagaming@riseup.net> | 2023-12-31 20:29:19 -0500 |
| commit | c5ea95a787565e56bce6d50b52cecef85ad5d177 (patch) | |
| tree | bd5b6d44cf09ab7271e95e41dd3dcefd3c0c5ffe /backend/decky_loader/wsrouter.py | |
| parent | db96121304e78ceb00f1db0eab5a2f098a6f419b (diff) | |
| download | decky-loader-c5ea95a787565e56bce6d50b52cecef85ad5d177.tar.gz decky-loader-c5ea95a787565e56bce6d50b52cecef85ad5d177.zip | |
finalize api for plugin events in backend
just need frontend impl now
Diffstat (limited to 'backend/decky_loader/wsrouter.py')
| -rw-r--r-- | backend/decky_loader/wsrouter.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/backend/decky_loader/wsrouter.py b/backend/decky_loader/wsrouter.py index 59cbe4a3..fa0707f7 100644 --- a/backend/decky_loader/wsrouter.py +++ b/backend/decky_loader/wsrouter.py @@ -1,3 +1,4 @@ +from _typeshed import DataclassInstance from logging import getLogger from asyncio import AbstractEventLoop, create_task @@ -8,7 +9,8 @@ from aiohttp.web import Application, WebSocketResponse, Request, Response, get from enum import IntEnum from typing import Callable, Coroutine, Dict, Any, cast, TypeVar, Type -from dataclasses import dataclass + +from dataclasses import asdict, is_dataclass from traceback import format_exc @@ -24,15 +26,9 @@ class MessageType(IntEnum): # WSMessage with slightly better typings class WSMessageExtra(WSMessage): + # TODO message typings here too data: Any type: WSMsgType -@dataclass -class Message: - data: Any - type: MessageType - -# @dataclass -# class CallMessage # see wsrouter.ts for typings @@ -133,7 +129,11 @@ class WSRouter: return ws # DataType defaults to None so that if a plugin opts in to strict pyright checking and attempts to pass data witbout specifying the type (or any), the type check fails - async def emit(self, event: str, data: DataType | None = None, data_type: Type[DataType]|None = None): + async def emit(self, event: str, data: DataType | None = None, data_type: Type[DataType] | None = None): self.logger.debug('Firing frontend event %s with args %s', data) + sent_data: Dict[Any, Any] | None = cast(Dict[Any, Any], data) + if is_dataclass(data): + data_as_dataclass = cast(DataclassInstance, data) + sent_data = asdict(data_as_dataclass) - await self.write({ "type": MessageType.EVENT.value, "event": event, "data": data }) + await self.write({ "type": MessageType.EVENT.value, "event": event, "data": sent_data }) |
