Files
NebulaShell/oss/plugin/manager.py
Starlight-apk e67d2d8ef6
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.13) (push) Has been cancelled
refactor: 优化 NBPF 模块 - 缓存导入/合并重复方法/减少I/O
- crypto.py: 8个_imp_*方法改为_ModuleCache类缓存导入
- crypto.py: outer/inner加解密合并为_layer_encrypt/decrypt
- crypto.py: 提取公共摘要计算方法,拆分长方法
- compiler.py: 删除_obfuscate_code中未使用的死代码
- loader.py: 3次ZIP扫描合并为1次缓存读取
- format.py: 更新为使用_ModuleCache
- 合计减少205行代码(1707→1502)
2026-05-17 15:36:45 +08:00

83 lines
2.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""插件管理器 - 直接使用框架层的 Core Engine"""
from typing import Any, Optional
from oss.core.engine import PluginManager as CorePluginManager
# 深度隐藏的成就系统导入
try:
from oss.core.achievements import get_validator
_ACHIEVEMENTS_ENABLED = True
except ImportError:
_ACHIEVEMENTS_ENABLED = False
class PluginManager:
"""极简插件管理器
直接使用框架层的 CorePluginManager原 Core 插件功能)
- 不再通过插件加载器加载 Core
- 所有核心功能直接集成在 oss.core.engine 中
"""
def __init__(self):
self.core = CorePluginManager()
def load(self):
"""加载所有插件(由 CorePluginManager 管理)"""
self.core.load_all()
# 隐藏成就:深海潜水员
if _ACHIEVEMENTS_ENABLED:
try:
validator = get_validator()
validator.unlock("deep_diver")
except Exception as e:
print(f"[PluginManager] 错误: {e}")
def start(self):
"""启动 Core它会初始化并启动所有其他插件"""
import time
start_time = time.time()
self.core.init_and_start_all()
# 启动 HTTP 服务
self.core.start_http_server()
# 启动防篡改监控
self.core.start_tamper_monitor()
# 计算启动时间并检查速度成就
elapsed_ms = (time.time() - start_time) * 1000
if _ACHIEVEMENTS_ENABLED:
try:
validator = get_validator()
validator.check_startup_speed(elapsed_ms)
# 检查插件数量成就
plugin_count = len(self.core.plugins)
validator.check_plugin_count(plugin_count)
except Exception as e:
print(f"[PluginManager] 错误: {e}")
def stop(self):
"""停止所有插件"""
try:
self.core.stop_tamper_monitor()
self.core.stop_http_server()
self.core.stop_all()
except KeyboardInterrupt:
print("[PluginManager] 用户中断停止过程")
except Exception as e:
import traceback
print(f"[PluginManager] 停止插件时出错:{type(e).__name__}: {e}")
traceback.print_exc()
# 隐藏成就:崩溃幸存者
if _ACHIEVEMENTS_ENABLED:
try:
validator = get_validator()
validator.track_progress("session_end")
except Exception as e:
print(f"[PluginManager] 错误: {e}")