- 新增启动弹窗通知(绿色主题,支持关闭) - 新增 StreamPreview 流式文本预览节点 - 新增 fileUpload、updateNotifier 前端 JS 模块 - 重构多个 client,统一错误处理 - 删除废弃节点 batch_nano_banana_v2、quan_neng_sheng_tu 等 - 将 .config 纳入版本控制(已清空密钥)
99 lines
2.7 KiB
Python
99 lines
2.7 KiB
Python
"""
|
|
更新检查工具
|
|
在插件加载时检查是否有新版本
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
from typing import Optional
|
|
|
|
|
|
def get_current_version() -> Optional[str]:
|
|
"""
|
|
获取当前版本号
|
|
|
|
Returns:
|
|
版本号字符串,如果读取失败返回 None
|
|
"""
|
|
version_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), "version.txt")
|
|
try:
|
|
with open(version_file, 'r', encoding='utf-8') as f:
|
|
return f.read().strip()
|
|
except Exception:
|
|
return None
|
|
|
|
|
|
def check_for_updates() -> bool:
|
|
"""
|
|
检查是否有更新
|
|
|
|
Returns:
|
|
True 如果有更新,False 如果已是最新或检查失败
|
|
"""
|
|
try:
|
|
# 获取当前目录
|
|
plugin_dir = os.path.dirname(os.path.dirname(__file__))
|
|
|
|
# 检查是否是 Git 仓库
|
|
git_dir = os.path.join(plugin_dir, '.git')
|
|
if not os.path.exists(git_dir):
|
|
return False
|
|
|
|
# 执行 git fetch(禁止弹出认证弹框,失败时静默处理)
|
|
env = os.environ.copy()
|
|
env['GIT_TERMINAL_PROMPT'] = '0'
|
|
subprocess.run(
|
|
['git', 'fetch', 'origin'],
|
|
cwd=plugin_dir,
|
|
capture_output=True,
|
|
timeout=10,
|
|
env=env
|
|
)
|
|
|
|
# 检查本地和远程版本
|
|
local = subprocess.run(
|
|
['git', 'rev-parse', '@'],
|
|
cwd=plugin_dir,
|
|
capture_output=True,
|
|
text=True
|
|
).stdout.strip()
|
|
|
|
remote = subprocess.run(
|
|
['git', 'rev-parse', '@{u}'],
|
|
cwd=plugin_dir,
|
|
capture_output=True,
|
|
text=True
|
|
).stdout.strip()
|
|
|
|
return local != remote
|
|
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
def notify_update_available():
|
|
"""通知用户有更新可用(前端弹窗 + 控制台)"""
|
|
current_version = get_current_version()
|
|
version_str = f" (当前版本: {current_version})" if current_version else ""
|
|
|
|
print(f"[comfyui_o1key] 有新版本可用{version_str}")
|
|
|
|
try:
|
|
import threading
|
|
from server import PromptServer
|
|
|
|
def _send():
|
|
try:
|
|
PromptServer.instance.send_sync(
|
|
"o1key.update_available",
|
|
{"message": "欢迎使用o1key工作流,祝您马年,马上有福,马上有钱,马到成功!!!"}
|
|
)
|
|
print("[o1key] 更新通知已发送到前端")
|
|
except Exception as e:
|
|
print(f"[o1key] 发送通知失败: {e}")
|
|
|
|
# 延迟 5 秒发送,确保前端 WebSocket 已连接
|
|
threading.Timer(5.0, _send).start()
|
|
except Exception:
|
|
pass
|