150 lines
4.3 KiB
Python
150 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
EU-Utility - Main Entry Point
|
|
|
|
Initializes the core services and manages the plugin system.
|
|
"""
|
|
|
|
import sys
|
|
import signal
|
|
from pathlib import Path
|
|
|
|
# Ensure core is importable
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
from core.plugin_api import PluginAPI
|
|
from core.clipboard import get_clipboard_manager
|
|
|
|
|
|
class EUUtility:
|
|
"""
|
|
Main application class for EU-Utility.
|
|
|
|
Responsibilities:
|
|
- Initialize core services (clipboard, etc.)
|
|
- Manage plugin lifecycle
|
|
- Handle graceful shutdown
|
|
"""
|
|
|
|
def __init__(self):
|
|
self.plugin_api = PluginAPI()
|
|
self.running = False
|
|
self._setup_signal_handlers()
|
|
|
|
def _setup_signal_handlers(self) -> None:
|
|
"""Setup handlers for graceful shutdown."""
|
|
signal.signal(signal.SIGINT, self._signal_handler)
|
|
signal.signal(signal.SIGTERM, self._signal_handler)
|
|
|
|
def _signal_handler(self, signum, frame) -> None:
|
|
"""Handle shutdown signals."""
|
|
print("\n[EU-Utility] Shutdown signal received...")
|
|
self.stop()
|
|
sys.exit(0)
|
|
|
|
def initialize(self, auto_start_clipboard_monitor: bool = False) -> None:
|
|
"""
|
|
Initialize EU-Utility core services.
|
|
|
|
Args:
|
|
auto_start_clipboard_monitor: Whether to monitor clipboard changes
|
|
"""
|
|
print("=" * 50)
|
|
print("EU-Utility - Initializing...")
|
|
print("=" * 50)
|
|
|
|
# Initialize clipboard manager (core service)
|
|
self._init_clipboard_service(auto_start_clipboard_monitor)
|
|
|
|
# Load plugins
|
|
self._load_plugins()
|
|
|
|
print("=" * 50)
|
|
print("EU-Utility - Ready")
|
|
print("=" * 50)
|
|
|
|
def _init_clipboard_service(self, auto_start_monitor: bool = False) -> None:
|
|
"""
|
|
Initialize the clipboard service.
|
|
This is a core service available to all plugins.
|
|
"""
|
|
print("[EU-Utility] Initializing clipboard service...")
|
|
|
|
clipboard_manager = self.plugin_api.register_clipboard_service(
|
|
auto_start_monitoring=auto_start_monitor
|
|
)
|
|
|
|
if clipboard_manager.is_available():
|
|
print("[EU-Utility] ✓ Clipboard service initialized")
|
|
stats = clipboard_manager.get_stats()
|
|
print(f" - History entries: {stats['history_count']}")
|
|
print(f" - Max history: {stats['max_history']}")
|
|
print(f" - Monitoring: {stats['is_monitoring']}")
|
|
else:
|
|
print("[EU-Utility] ⚠ Clipboard service unavailable (pyperclip not installed)")
|
|
|
|
def _load_plugins(self) -> None:
|
|
"""Load plugins from the plugins directory."""
|
|
print("[EU-Utility] Loading plugins...")
|
|
plugins = self.plugin_api.load_plugins_from_directory("plugins")
|
|
|
|
if plugins:
|
|
print(f"[EU-Utility] Loaded {len(plugins)} plugin(s)")
|
|
for plugin in plugins:
|
|
print(f" - {plugin.name} v{plugin.version}")
|
|
else:
|
|
print("[EU-Utility] No plugins found")
|
|
|
|
# Start all plugins
|
|
self.plugin_api.start_all()
|
|
|
|
def run(self) -> None:
|
|
"""
|
|
Run the main application loop.
|
|
Blocks until stop() is called.
|
|
"""
|
|
self.running = True
|
|
|
|
try:
|
|
while self.running:
|
|
# Main loop - can be extended for CLI, GUI, etc.
|
|
# For now, just keep alive with sleep
|
|
import time
|
|
time.sleep(0.1)
|
|
except KeyboardInterrupt:
|
|
pass
|
|
finally:
|
|
self.stop()
|
|
|
|
def stop(self) -> None:
|
|
"""Stop EU-Utility and cleanup resources."""
|
|
if not self.running and not self.plugin_api.get_all_plugins():
|
|
return
|
|
|
|
print("\n[EU-Utility] Shutting down...")
|
|
|
|
# Stop all plugins
|
|
self.plugin_api.stop_all()
|
|
|
|
self.running = False
|
|
print("[EU-Utility] Goodbye!")
|
|
|
|
def get_clipboard_manager(self):
|
|
"""Get the clipboard manager instance."""
|
|
return self.plugin_api.get_clipboard_manager()
|
|
|
|
|
|
def main():
|
|
"""Main entry point."""
|
|
app = EUUtility()
|
|
|
|
# Initialize with clipboard monitoring enabled
|
|
app.initialize(auto_start_clipboard_monitor=True)
|
|
|
|
# Run the application
|
|
app.run()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|