性能优化 (#2126)

* 性能优化

* 代码改进

* 优化浏览器代际切换逻辑

* 统一缓存与生命周期

* 添加aiomysql依赖

* 优化插件路径处理逻辑,简化条件判断;在虚拟环境包管理器中添加编码和错误处理参数以增强稳定性

* 🚨 auto fix by pre-commit hooks

* 优化Windows下的关闭逻辑

* 代码优化

* bugfix:修复配置重载问题

* bugfix:修复插件加载启动竞态问题

* 收敛事件入口和权限上下文

* 优化 Windows launcher 关闭重启兜底

---------

Co-authored-by: HibiKier <775757368@qq.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Copaan
2026-04-26 15:50:15 +08:00
committed by GitHub
co-authored by HibiKier pre-commit-ci[bot]
parent 24c316cd2c
commit 5d92ccd3b0
56 changed files with 3092 additions and 806 deletions
@@ -8,6 +8,7 @@ from zhenxun.configs.config import Config
from zhenxun.services.log import logger
LOG_COMMAND = "VirtualEnvPackageManager"
PROJECT_ROOT = Path(__file__).resolve().parents[3]
Config.add_plugin_config(
"virtualenv",
@@ -191,6 +192,46 @@ class VirtualEnvPackageManager:
)
return stderr
@classmethod
async def add_requirement(cls, requirement_file: Path):
"""将依赖文件写入项目依赖并同步环境
插件商店安装依赖需要持久化到 pyproject.toml/uv.lock,避免重建环境后丢失。
"""
if not requirement_file.exists():
raise FileNotFoundError(f"依赖文件 {requirement_file} 不存在", LOG_COMMAND)
cls._clean_requirements_file(requirement_file)
try:
command = [
"uv",
"add",
"--requirements",
str(requirement_file.absolute()),
]
logger.info(f"执行项目依赖添加指令: {command}", LOG_COMMAND)
result = await asyncio.to_thread(
subprocess.run,
command,
cwd=PROJECT_ROOT,
check=True,
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
)
logger.debug(
f"项目依赖添加指令执行完成: {result.stdout}",
LOG_COMMAND,
)
return result.stdout
except (CalledProcessError, FileNotFoundError) as e:
stderr = e.stderr if isinstance(e, CalledProcessError) else str(e)
logger.error(
f"项目依赖添加指令执行失败: {stderr}.",
LOG_COMMAND,
)
return stderr
@classmethod
async def list(cls) -> str:
"""列出已安装的依赖包"""