41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
from pathlib import Path
|
|
from watchdog.observers import Observer
|
|
from watchdog.events import FileSystemEventHandler
|
|
from log.Logger import *
|
|
logger = Logger()
|
|
|
|
class PluginFSHandler(FileSystemEventHandler):
|
|
def __init__(self, manager):
|
|
self.manager = manager
|
|
|
|
def on_modified(self, event):
|
|
try:
|
|
if event.is_directory:
|
|
return
|
|
if event.src_path.endswith(".lua"):
|
|
logger.log_lua_info(f"Plugin changed: {event.src_path}, reloading")
|
|
self.manager.reload_plugin(Path(event.src_path))
|
|
except Exception as e:
|
|
logger.log_lua_error(f"Error in on_modified: {e}")
|
|
|
|
def on_created(self, event):
|
|
try:
|
|
if event.is_directory:
|
|
return
|
|
if event.src_path.endswith(".lua"):
|
|
logger.log_lua_info(f"New plugin: {event.src_path}, loading")
|
|
self.manager.load_plugin(Path(event.src_path))
|
|
except Exception as e:
|
|
logger.error(f"Error in on_created: {e}")
|
|
|
|
def on_deleted(self, event):
|
|
try:
|
|
if event.is_directory:
|
|
return
|
|
p = Path(event.src_path)
|
|
if p.suffix == ".lua":
|
|
logger.log_lua_info(f"Plugin removed: {p.name}")
|
|
self.manager.unload_plugin(p.name)
|
|
except Exception as e:
|
|
logger.log_lua_error(f"Error in on_deleted: {e}")
|