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}")
|
logger.info(f"Found plugin: {module_name} in {plugin_dir}")
|
||||||
metadata = self._load_plugin_metadata(metadata_file)
|
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(
|
plugin_info = PluginInfo(
|
||||||
metadata.get('name', module_name),
|
metadata.get('name', module_name),
|
||||||
module_name,
|
module_name,
|
||||||
@ -195,8 +206,29 @@ class PluginSystemManager:
|
|||||||
|
|
||||||
logger.info(f"Adding plugin to registry: {module_name}")
|
logger.info(f"Adding plugin to registry: {module_name}")
|
||||||
self._plugins[module_name] = plugin_info
|
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:
|
else:
|
||||||
logger.warning(f"No plugin file found in directory: {plugin_dir}")
|
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):
|
def _load_plugin_metadata(self, metadata_file):
|
||||||
"""Load plugin metadata from a file."""
|
"""Load plugin metadata from a file."""
|
||||||
|
@ -33,12 +33,26 @@ class HelloWorld(Plugin):
|
|||||||
logger.info("Activating Hello World plugin")
|
logger.info("Activating Hello World plugin")
|
||||||
|
|
||||||
# Register our keyboard shortcut
|
# Register our keyboard shortcut
|
||||||
self.registerGestureByString(
|
if hasattr(self, 'registerGestureByString'):
|
||||||
self.speakTest,
|
logger.info("Registering keyboard shortcut kb:cthulhu+z")
|
||||||
"hello world",
|
self.registerGestureByString(
|
||||||
"kb:cthulhu+z",
|
self.speakTest,
|
||||||
learnModeEnabled=True
|
"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:
|
except Exception as e:
|
||||||
logger.error(f"Error activating Hello World plugin: {e}")
|
logger.error(f"Error activating Hello World plugin: {e}")
|
||||||
|
|
||||||
@ -56,14 +70,28 @@ class HelloWorld(Plugin):
|
|||||||
|
|
||||||
def speakTest(self, script=None, inputEvent=None):
|
def speakTest(self, script=None, inputEvent=None):
|
||||||
"""Speak a test message."""
|
"""Speak a test message."""
|
||||||
|
logger.info("speakTest called from hello_world plugin")
|
||||||
try:
|
try:
|
||||||
if self.app:
|
if self.app:
|
||||||
self.app.getDynamicApiManager().getAPI('CthulhuState').activeScript.presentMessage(
|
dynamicApi = self.app.getDynamicApiManager()
|
||||||
'hello world',
|
if dynamicApi:
|
||||||
resetStyles=False
|
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
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in speakTest: {e}")
|
logger.error(f"Error in speakTest: {e}")
|
||||||
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
return False
|
return False
|
||||||
|
@ -51,18 +51,30 @@ class SelfVoice(Plugin):
|
|||||||
self.voiceThread.daemon = True # Make thread exit when main thread exits
|
self.voiceThread.daemon = True # Make thread exit when main thread exits
|
||||||
|
|
||||||
@cthulhu_hookimpl
|
@cthulhu_hookimpl
|
||||||
def activate(self):
|
def activate(self, plugin=None):
|
||||||
"""Activate the self-voice plugin."""
|
"""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")
|
logger.info("Activating Self Voice Plugin")
|
||||||
self.activateWorker()
|
try:
|
||||||
|
self.activateWorker()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error activating Self Voice plugin: {e}")
|
||||||
|
|
||||||
@cthulhu_hookimpl
|
@cthulhu_hookimpl
|
||||||
def deactivate(self):
|
def deactivate(self, plugin=None):
|
||||||
"""Deactivate the self-voice plugin."""
|
"""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")
|
logger.info("Deactivating Self Voice Plugin")
|
||||||
self.deactivateWorker()
|
try:
|
||||||
super().deactivate()
|
self.deactivateWorker()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error deactivating Self Voice plugin: {e}")
|
||||||
|
|
||||||
def activateWorker(self):
|
def activateWorker(self):
|
||||||
"""Start the voice worker thread."""
|
"""Start the voice worker thread."""
|
||||||
|
@ -413,4 +413,4 @@ presentChatRoomLast = False
|
|||||||
presentLiveRegionFromInactiveTab = False
|
presentLiveRegionFromInactiveTab = False
|
||||||
|
|
||||||
# Plugins
|
# 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