attempt to add plugin events to the plugin frontend api.

unable to test right now though
This commit is contained in:
Party Wumpus
2024-04-09 15:44:38 +01:00
committed by PartyWumpus
parent de9d2144a6
commit f9ff518e6d
6 changed files with 57 additions and 21 deletions
+3 -11
View File
@@ -8,7 +8,6 @@ from typing import Any, Tuple, Dict
from aiohttp import web
from os.path import exists
from attr import dataclass
from watchdog.events import RegexMatchingEventHandler, DirCreatedEvent, DirModifiedEvent, FileCreatedEvent, FileModifiedEvent # type: ignore
from watchdog.observers import Observer # type: ignore
@@ -66,12 +65,6 @@ class FileChangeHandler(RegexMatchingEventHandler):
self.logger.debug(f"file modified: {src_path}")
self.maybe_reload(src_path)
@dataclass
class PluginEvent:
plugin_name: str
event: str
data: str
class Loader:
def __init__(self, server_instance: PluginManager, ws: WSRouter, plugin_path: str, loop: AbstractEventLoop, live_reload: bool = False) -> None:
self.loop = loop
@@ -149,10 +142,9 @@ class Loader:
def import_plugin(self, file: str, plugin_directory: str, refresh: bool | None = False, batch: bool | None = False):
try:
async def plugin_emitted_event(event: str, data: Any):
self.logger.debug(f"PLUGIN EMITTED EVENT: {str(event)} {data}")
event_data = PluginEvent(plugin_name=plugin.name, event=event, data=data)
await self.ws.emit("loader/plugin_event", event_data)
async def plugin_emitted_event(event: str, args: Any):
self.logger.debug(f"PLUGIN EMITTED EVENT: {event} with args {args}")
await self.ws.emit(f"loader/plugin_event", {plugin:plugin.name, event:event, args:args})
plugin = PluginWrapper(file, plugin_directory, self.plugin_path, plugin_emitted_event)
if plugin.name in self.plugins: