feat: 新增新版本检测蓝色弹框通知

This commit is contained in:
Jony
2026-04-13 01:00:53 +08:00
parent 92bcf65d14
commit 82752d34fc
3 changed files with 114 additions and 1 deletions
+41
View File
@@ -71,6 +71,47 @@ def check_for_updates() -> bool:
return False
def get_update_changelog() -> list:
"""获取远程新版本的 commit 摘要(最多3条)"""
try:
plugin_dir = os.path.dirname(os.path.dirname(__file__))
result = subprocess.run(
['git', 'log', 'HEAD..origin/main', '--pretty=format:%s', '--no-merges'],
cwd=plugin_dir,
capture_output=True,
text=True,
encoding='utf-8'
)
lines = [l.strip() for l in result.stdout.strip().splitlines() if l.strip()]
return lines[:3]
except Exception:
return []
def notify_new_version():
"""检测到新版本时,推送蓝色更新通知弹框"""
changelog = get_update_changelog()
print("[o1key] 检测到新版本,准备推送更新通知")
try:
import threading
from server import PromptServer
def _send():
try:
PromptServer.instance.send_sync(
"o1key.new_version",
{"changelog": changelog}
)
print("[o1key] 新版本通知已发送到前端")
except Exception as e:
print(f"[o1key] 发送新版本通知失败: {e}")
threading.Timer(5.0, _send).start()
except Exception:
pass
def notify_update_available():
"""通知用户有更新可用(前端弹窗 + 控制台)"""
current_version = get_current_version()