优化: 1. 修复SSL警告问题 2. 优化加载对话框显示逻辑 3. 添加API测试工具
This commit is contained in:
@@ -44,6 +44,7 @@ class LoadingDialog(QDialog):
|
||||
self.progress_bar = QProgressBar()
|
||||
self.progress_bar.setTextVisible(False)
|
||||
self.progress_bar.setRange(0, 0) # 设置为循环模式
|
||||
self.progress_bar.setMinimumWidth(250) # 设置最小宽度
|
||||
layout.addWidget(self.progress_bar)
|
||||
|
||||
self.setLayout(layout)
|
||||
@@ -63,13 +64,54 @@ class LoadingDialog(QDialog):
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
min-height: 12px;
|
||||
}
|
||||
QProgressBar::chunk {
|
||||
background-color: #0d6efd;
|
||||
width: 10px;
|
||||
width: 15px;
|
||||
margin: 0.5px;
|
||||
}
|
||||
""")
|
||||
|
||||
# 添加定时器以自动更新进度条动画
|
||||
self.timer = QTimer(self)
|
||||
self.timer.timeout.connect(self.update_progress)
|
||||
self.progress_value = 0
|
||||
|
||||
def update_progress(self):
|
||||
"""更新进度条动画"""
|
||||
self.progress_value = (self.progress_value + 1) % 100
|
||||
self.progress_bar.setValue(self.progress_value)
|
||||
|
||||
def showEvent(self, event):
|
||||
"""显示时启动定时器"""
|
||||
super().showEvent(event)
|
||||
self.timer.start(50) # 每50毫秒更新一次
|
||||
|
||||
def hideEvent(self, event):
|
||||
"""隐藏时停止定时器"""
|
||||
self.timer.stop()
|
||||
super().hideEvent(event)
|
||||
|
||||
def check_status(self):
|
||||
"""检查会员状态(从API获取)"""
|
||||
try:
|
||||
# 只在首次检查时显示加载对话框,并设置更明确的提示
|
||||
if self._activation_status is None:
|
||||
self.show_loading_dialog("正在连接服务器,请稍候...")
|
||||
|
||||
# 创建工作线程
|
||||
self.worker = ApiWorker(self.switcher.get_member_status)
|
||||
self.worker.finished.connect(self.on_status_check_complete)
|
||||
self.worker.start()
|
||||
|
||||
except Exception as e:
|
||||
if self._activation_status is None:
|
||||
self.hide_loading_dialog()
|
||||
QMessageBox.critical(self, "错误", f"检查状态失败: {str(e)}")
|
||||
self._activation_status = False
|
||||
logging.error(f"检查状态时发生错误: {str(e)}")
|
||||
return False
|
||||
|
||||
class ApiWorker(QThread):
|
||||
"""API请求工作线程"""
|
||||
@@ -313,35 +355,41 @@ class MainWindow(QMainWindow):
|
||||
|
||||
def show_loading_dialog(self, message="请稍候..."):
|
||||
"""显示加载对话框"""
|
||||
self.loading_dialog = LoadingDialog(self, message)
|
||||
self.loading_dialog.setStyleSheet("""
|
||||
QDialog {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
QLabel {
|
||||
color: #0d6efd;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
padding: 10px;
|
||||
}
|
||||
QProgressBar {
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
QProgressBar::chunk {
|
||||
background-color: #0d6efd;
|
||||
width: 10px;
|
||||
margin: 0.5px;
|
||||
}
|
||||
""")
|
||||
if not hasattr(self, 'loading_dialog') or not self.loading_dialog:
|
||||
self.loading_dialog = LoadingDialog(self, message)
|
||||
self.loading_dialog.setStyleSheet("""
|
||||
QDialog {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
QLabel {
|
||||
color: #0d6efd;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
padding: 10px;
|
||||
}
|
||||
QProgressBar {
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
QProgressBar::chunk {
|
||||
background-color: #0d6efd;
|
||||
width: 10px;
|
||||
margin: 0.5px;
|
||||
}
|
||||
""")
|
||||
else:
|
||||
self.loading_dialog.message_label.setText(message)
|
||||
self.loading_dialog.show()
|
||||
QApplication.processEvents() # 确保对话框立即显示
|
||||
|
||||
def hide_loading_dialog(self):
|
||||
"""隐藏加载对话框"""
|
||||
if hasattr(self, 'loading_dialog'):
|
||||
if hasattr(self, 'loading_dialog') and self.loading_dialog:
|
||||
self.loading_dialog.hide()
|
||||
self.loading_dialog.deleteLater()
|
||||
self.loading_dialog = None
|
||||
QApplication.processEvents() # 确保对话框立即隐藏
|
||||
|
||||
def activate_account(self):
|
||||
"""激活账号"""
|
||||
@@ -512,7 +560,7 @@ class MainWindow(QMainWindow):
|
||||
|
||||
if isinstance(data, tuple):
|
||||
success, message, account_info = data
|
||||
if success:
|
||||
if success and account_info is not None:
|
||||
# 更新会员信息显示
|
||||
self.update_status_display(account_info)
|
||||
# 更新激活状态缓存
|
||||
@@ -603,20 +651,10 @@ class MainWindow(QMainWindow):
|
||||
}
|
||||
""")
|
||||
msg.exec_()
|
||||
# 更新显示为未激活状态
|
||||
self.update_status_display(account_info)
|
||||
# 所有失败情况都不更新状态显示
|
||||
else:
|
||||
QMessageBox.critical(self, "错误", f"激活失败: {data}")
|
||||
# 更新为未激活状态
|
||||
device_info = self.switcher.get_device_info()
|
||||
inactive_status = {
|
||||
"status": "inactive",
|
||||
"expire_time": "",
|
||||
"total_days": 0,
|
||||
"days_left": 0,
|
||||
"device_info": device_info
|
||||
}
|
||||
self.update_status_display(inactive_status)
|
||||
# 不更新状态显示
|
||||
|
||||
def update_status_display(self, status_info: dict):
|
||||
"""更新状态显示"""
|
||||
@@ -660,7 +698,7 @@ class MainWindow(QMainWindow):
|
||||
try:
|
||||
# 只在首次检查时显示加载对话框
|
||||
if self._activation_status is None:
|
||||
self.show_loading_dialog("正在检查会员状态,请稍候...")
|
||||
self.show_loading_dialog("正在连接服务器...")
|
||||
|
||||
# 创建工作线程
|
||||
self.worker = ApiWorker(self.switcher.get_member_status)
|
||||
|
||||
Reference in New Issue
Block a user