Fixed some more issues with plugins. Fixed bugs in self_voice
This commit is contained in:
@ -182,6 +182,17 @@ class PluginSystemManager:
|
||||
logger.info(f"Found plugin: {module_name} in {plugin_dir}")
|
||||
metadata = self._load_plugin_metadata(metadata_file)
|
||||
|
||||
# Try to get the actual plugin class name from the plugin file
|
||||
class_name = self._get_plugin_class_name(plugin_file)
|
||||
if class_name:
|
||||
logger.info(f"Found plugin class: {class_name} in {plugin_file}")
|
||||
# Use the class name instead of module name for more accurate registration
|
||||
if class_name != module_name:
|
||||
logger.info(f"Using class name {class_name} instead of module name {module_name}")
|
||||
# Store both to allow flexible access
|
||||
metadata['module_name'] = module_name
|
||||
module_name = class_name
|
||||
|
||||
plugin_info = PluginInfo(
|
||||
metadata.get('name', module_name),
|
||||
module_name,
|
||||
@ -195,9 +206,30 @@ class PluginSystemManager:
|
||||
|
||||
logger.info(f"Adding plugin to registry: {module_name}")
|
||||
self._plugins[module_name] = plugin_info
|
||||
|
||||
# Also register with lowercase name for case-insensitive access
|
||||
if module_name.lower() != module_name:
|
||||
logger.info(f"Also registering lowercase alias: {module_name.lower()}")
|
||||
self._plugins[module_name.lower()] = plugin_info
|
||||
else:
|
||||
logger.warning(f"No plugin file found in directory: {plugin_dir}")
|
||||
|
||||
def _get_plugin_class_name(self, plugin_file):
|
||||
"""Extract the plugin class name from a plugin file."""
|
||||
try:
|
||||
with open(plugin_file, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Simple regex-like search for class definition that inherits from Plugin
|
||||
import re
|
||||
matches = re.findall(r'class\s+(\w+)\s*\([^)]*Plugin[^)]*\)', content)
|
||||
if matches:
|
||||
return matches[0]
|
||||
except Exception as e:
|
||||
logger.error(f"Error extracting plugin class name from {plugin_file}: {e}")
|
||||
|
||||
return None
|
||||
|
||||
def _load_plugin_metadata(self, metadata_file):
|
||||
"""Load plugin metadata from a file."""
|
||||
metadata = {}
|
||||
|
@ -33,12 +33,26 @@ class HelloWorld(Plugin):
|
||||
logger.info("Activating Hello World plugin")
|
||||
|
||||
# Register our keyboard shortcut
|
||||
if hasattr(self, 'registerGestureByString'):
|
||||
logger.info("Registering keyboard shortcut kb:cthulhu+z")
|
||||
self.registerGestureByString(
|
||||
self.speakTest,
|
||||
"hello world",
|
||||
"kb:cthulhu+z",
|
||||
learnModeEnabled=True
|
||||
)
|
||||
elif self.app and hasattr(self.app, 'getAPIHelper'):
|
||||
helper = self.app.getAPIHelper()
|
||||
if helper:
|
||||
logger.info("Registering keyboard shortcut kb:cthulhu+z via API helper")
|
||||
helper.registerGestureByString(
|
||||
self.speakTest,
|
||||
"hello world",
|
||||
"kb:cthulhu+z",
|
||||
learnModeEnabled=True
|
||||
)
|
||||
else:
|
||||
logger.error("Cannot register keyboard shortcut - no API helper available")
|
||||
except Exception as e:
|
||||
logger.error(f"Error activating Hello World plugin: {e}")
|
||||
|
||||
@ -56,14 +70,28 @@ class HelloWorld(Plugin):
|
||||
|
||||
def speakTest(self, script=None, inputEvent=None):
|
||||
"""Speak a test message."""
|
||||
logger.info("speakTest called from hello_world plugin")
|
||||
try:
|
||||
if self.app:
|
||||
self.app.getDynamicApiManager().getAPI('CthulhuState').activeScript.presentMessage(
|
||||
dynamicApi = self.app.getDynamicApiManager()
|
||||
if dynamicApi:
|
||||
state = dynamicApi.getAPI('CthulhuState')
|
||||
if state and state.activeScript:
|
||||
logger.info("Presenting message: 'hello world'")
|
||||
state.activeScript.presentMessage(
|
||||
'hello world',
|
||||
resetStyles=False
|
||||
)
|
||||
else:
|
||||
logger.error("No active script available")
|
||||
else:
|
||||
logger.error("No dynamic API manager available")
|
||||
else:
|
||||
logger.error("No app reference available")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error in speakTest: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
return False
|
||||
|
@ -51,18 +51,30 @@ class SelfVoice(Plugin):
|
||||
self.voiceThread.daemon = True # Make thread exit when main thread exits
|
||||
|
||||
@cthulhu_hookimpl
|
||||
def activate(self):
|
||||
def activate(self, plugin=None):
|
||||
"""Activate the self-voice plugin."""
|
||||
super().activate()
|
||||
# Skip if this activation call isn't for us
|
||||
if plugin is not None and plugin is not self:
|
||||
return
|
||||
|
||||
logger.info("Activating Self Voice Plugin")
|
||||
try:
|
||||
self.activateWorker()
|
||||
except Exception as e:
|
||||
logger.error(f"Error activating Self Voice plugin: {e}")
|
||||
|
||||
@cthulhu_hookimpl
|
||||
def deactivate(self):
|
||||
def deactivate(self, plugin=None):
|
||||
"""Deactivate the self-voice plugin."""
|
||||
# Skip if this deactivation call isn't for us
|
||||
if plugin is not None and plugin is not self:
|
||||
return
|
||||
|
||||
logger.info("Deactivating Self Voice Plugin")
|
||||
try:
|
||||
self.deactivateWorker()
|
||||
super().deactivate()
|
||||
except Exception as e:
|
||||
logger.error(f"Error deactivating Self Voice plugin: {e}")
|
||||
|
||||
def activateWorker(self):
|
||||
"""Start the voice worker thread."""
|
||||
|
@ -413,4 +413,4 @@ presentChatRoomLast = False
|
||||
presentLiveRegionFromInactiveTab = False
|
||||
|
||||
# Plugins
|
||||
activePlugins = ['Clipboard', 'DisplayVersion', 'MouseReview', 'Date', 'ByeCthulhu', 'Time', 'HelloCthulhu', 'hello_world', 'self_voice', 'PluginManager', 'SimplePluginSystem']
|
||||
activePlugins = ['Clipboard', 'DisplayVersion', 'MouseReview', 'Date', 'ByeCthulhu', 'Time', 'HelloCthulhu', 'hello_world', 'SelfVoice', 'PluginManager', 'SimplePluginSystem']
|
||||
|
Reference in New Issue
Block a user