[patch] 优化版本管理显示 与 更新提示(修改表名信息) 修复因线程安全问题导致的崩溃

This commit is contained in:
2025-10-10 15:34:26 +08:00
parent 6ad58b81b0
commit 12c1b1dfb8
3 changed files with 81 additions and 10 deletions

View File

@@ -372,10 +372,13 @@ class DatabaseVersionManager:
f"+{stats['lines_added']}/-{stats['lines_deleted']}")
# 6. 创建版本记录
# 生成下载地址(可配置
# download_url = f"https://shuidrop.com/download/gui/v{next_version}"
# 如果需要临时测试,可以改为:
download_url = "https://www.baidu.com"
# 生成下载地址(标准格式:指向实际安装包文件
installer_filename = f"ShuiDi_AI_Assistant_Setup_v{next_version}.exe"
download_url = f"https://shuidrop.com/download/gui/{installer_filename}"
# 完整示例: https://shuidrop.com/download/gui/ShuiDi_AI_Assistant_Setup_v1.4.12.exe
# 临时测试可以改为:
# download_url = "https://www.baidu.com"
version_record = {
'version': next_version,

View File

@@ -24,10 +24,31 @@ class NSISInstaller:
# 应用程序信息
self.app_name = "水滴AI客服智能助手"
self.app_name_en = "ShuiDi AI Assistant"
self.app_version = "1.0.0"
# 从 config.py 读取版本号(自动同步)
self.app_version = self._get_version_from_config()
self.app_publisher = "水滴智能科技"
self.app_url = "https://shuidrop.com/"
self.exe_name = "main.exe"
def _get_version_from_config(self):
"""从 config.py 读取版本号"""
try:
config_file = self.project_root / "config.py"
if config_file.exists():
with open(config_file, 'r', encoding='utf-8') as f:
content = f.read()
import re
match = re.search(r'APP_VERSION\s*=\s*["\']([^"\']+)["\']', content)
if match:
version = match.group(1)
print(f"📦 从 config.py 读取版本号: v{version}")
return version
except Exception as e:
print(f"⚠️ 读取版本号失败: {e},使用默认版本")
return "1.0.0"
def check_prerequisites(self):
"""检查构建前提条件"""
@@ -125,8 +146,11 @@ class NSISInstaller:
"""生成NSIS安装脚本"""
print("📝 生成NSIS安装脚本...")
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
installer_name = f"{self.app_name_en}_Setup_{self.app_version}_{timestamp}.exe"
# 标准化安装包命名(不带时间戳,便于固定下载地址)
installer_name = f"{self.app_name_en}_Setup_v{self.app_version}.exe"
# 示例: ShuiDi_AI_Assistant_Setup_v1.4.12.exe
print(f"📦 安装包名称: {installer_name}")
nsis_content = f'''# 水滴AI客服智能助手 NSIS 安装脚本
# 自动生成于 {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}

50
main.py
View File

@@ -753,24 +753,38 @@ class LoginWindow(QMainWindow):
self.add_log(f"🔔 准备显示更新通知: v{latest_version}", "INFO")
self.add_log(f" 下载地址: {download_url if download_url else '(空)'}", "INFO")
# 读取更新内容
update_content = self._get_update_content(latest_version)
# 检查下载地址
if not download_url or download_url.strip() == "":
# 下载地址为空,只显示通知,不提供下载
message = f"发现新版本 {latest_version}\n\n"
if update_content:
message += f"更新内容:\n{update_content}\n\n"
message += "下载地址暂未配置,请稍后再试或联系管理员。"
QMessageBox.information(
self,
"版本更新",
f"发现新版本 {latest_version}\n\n"
f"下载地址暂未配置,请稍后再试或联系管理员。",
message,
QMessageBox.Ok
)
self.add_log(f"⚠️ 新版本 {latest_version} 的下载地址为空,已通知用户", "WARNING")
return # 安全返回,不崩溃
# 下载地址有效,显示更新对话框
message = f"发现新版本 {latest_version},是否立即更新?\n\n"
if update_content:
message += f"更新内容:\n{update_content}\n\n"
message += "点击确定将打开下载页面。"
reply = QMessageBox.question(
self,
"版本更新",
f"发现新版本 {latest_version},是否立即更新?\n\n点击确定将打开下载页面。",
message,
QMessageBox.Yes | QMessageBox.No,
QMessageBox.Yes
)
@@ -786,6 +800,36 @@ class LoginWindow(QMainWindow):
self.add_log(f"❌ 显示更新通知失败: {e}", "ERROR")
import traceback
self.add_log(f"详细错误: {traceback.format_exc()}", "ERROR")
def _get_update_content(self, version):
"""获取版本更新内容"""
try:
import json
version_file = "version_history.json"
if not os.path.exists(version_file):
return ""
with open(version_file, 'r', encoding='utf-8') as f:
history = json.load(f)
# 查找对应版本
for record in history:
if record.get('version') == version:
content = record.get('content', '')
# 去掉 [patch]/[minor]/[major] 标记
import re
content = re.sub(r'\[(patch|minor|major)\]\s*', '', content, flags=re.IGNORECASE)
# 限制长度
if len(content) > 150:
content = content[:150] + "..."
return content
return ""
except Exception as e:
self.add_log(f"⚠️ 读取更新内容失败: {e}", "DEBUG")
return ""
def trigger_update(self, download_url, latest_version):
"""触发更新下载"""