mirror of
https://github.com/hyb-oyqq/FRAISEMOE-Addons-Installer-NEXT.git
synced 2025-12-19 13:28:36 +00:00
feat(core): 更新窗口状态管理,统一使用window_manager
- 在多个模块中,将安装按钮状态管理从ui_manager迁移至window_manager,确保窗口状态的一致性和可维护性。 - 优化了ExtractionHandler、CloudflareOptimizer、DownloadManager、OfflineModeManager、PatchDetector等类中的状态更新逻辑,提升了代码的可读性和一致性。
This commit is contained in:
@@ -110,7 +110,8 @@ class ExtractionHandler:
|
||||
self.main_window.download_manager.on_extraction_finished(True)
|
||||
else:
|
||||
# 用户选择停止,保持窗口启用状态
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
# 通知DownloadManager停止下载队列
|
||||
self.main_window.download_manager.on_extraction_finished(False)
|
||||
return
|
||||
|
||||
@@ -199,7 +199,8 @@ class CloudflareOptimizer:
|
||||
|
||||
# 恢复主窗口状态
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
|
||||
# 显示取消消息
|
||||
QtWidgets.QMessageBox.information(
|
||||
@@ -332,7 +333,8 @@ class CloudflareOptimizer:
|
||||
if msg_box.clickedButton() == cancel_button:
|
||||
# 恢复主窗口状态
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return False
|
||||
|
||||
# 用户点击了继续,重新禁用主窗口
|
||||
@@ -403,7 +405,8 @@ class CloudflareOptimizer:
|
||||
if msg_box.clickedButton() == cancel_button:
|
||||
# 恢复主窗口状态
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return False
|
||||
else:
|
||||
QtWidgets.QMessageBox.critical(
|
||||
@@ -412,7 +415,8 @@ class CloudflareOptimizer:
|
||||
"\n修改hosts文件失败,请检查程序是否以管理员权限运行。\n"
|
||||
)
|
||||
# 恢复主窗口状态
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return False
|
||||
|
||||
# 用户点击了继续,重新禁用主窗口
|
||||
|
||||
@@ -63,7 +63,8 @@ class DownloadManager:
|
||||
)
|
||||
return
|
||||
|
||||
self.main_window.ui_manager.set_install_button_state("installing")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_INSTALLING)
|
||||
|
||||
self.main_window.setEnabled(False)
|
||||
|
||||
@@ -264,7 +265,8 @@ class DownloadManager:
|
||||
self.main_window, f"通知 - {APP_NAME}", "\n未在选择的目录中找到支持的游戏\n"
|
||||
)
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return
|
||||
|
||||
# 检查是否禁用了安装前哈希预检查
|
||||
@@ -479,7 +481,8 @@ class DownloadManager:
|
||||
else:
|
||||
if debug_mode:
|
||||
logger.debug("DEBUG: 用户取消了游戏选择")
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
else:
|
||||
# 如果没有可安装的游戏,显示提示
|
||||
if already_installed_games:
|
||||
@@ -492,7 +495,8 @@ class DownloadManager:
|
||||
f"通知 - {APP_NAME}",
|
||||
msg
|
||||
)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
|
||||
def _continue_download_after_config_fetch(self, data, error, selected_game_dirs):
|
||||
"""云端配置获取完成后继续下载流程
|
||||
@@ -530,7 +534,8 @@ class DownloadManager:
|
||||
self.main_window, f"错误 - {APP_NAME}", "\n网络状态异常或服务器故障,请重试\n"
|
||||
)
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return
|
||||
|
||||
self._fill_download_queue(config, selected_game_dirs)
|
||||
@@ -703,7 +708,8 @@ class DownloadManager:
|
||||
clicked_button = msg_box.clickedButton()
|
||||
if clicked_button == cancel_button:
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
self.download_queue.clear()
|
||||
return
|
||||
|
||||
@@ -958,7 +964,8 @@ class DownloadManager:
|
||||
logger.info("下载已全部停止。")
|
||||
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
|
||||
QtWidgets.QMessageBox.information(
|
||||
self.main_window,
|
||||
@@ -1002,7 +1009,8 @@ class DownloadManager:
|
||||
self.main_window, f"通知 - {APP_NAME}", "\n未在选择的目录中找到支持的游戏\n"
|
||||
)
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return
|
||||
|
||||
# 过滤出存在的游戏目录
|
||||
@@ -1013,7 +1021,8 @@ class DownloadManager:
|
||||
self.main_window, f"通知 - {APP_NAME}", "\n未找到指定游戏的安装目录\n"
|
||||
)
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return
|
||||
|
||||
self.main_window.setEnabled(False)
|
||||
@@ -1025,7 +1034,8 @@ class DownloadManager:
|
||||
self.main_window, f"错误 - {APP_NAME}", "\n网络状态异常或服务器故障,请重试\n"
|
||||
)
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return
|
||||
|
||||
# 填充下载队列
|
||||
@@ -1150,7 +1160,8 @@ class DownloadManager:
|
||||
|
||||
if not game_dirs:
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
from config.config import APP_NAME
|
||||
QMessageBox.warning(
|
||||
|
||||
@@ -847,7 +847,8 @@ class OfflineModeManager:
|
||||
QMessageBox.StandardButton.Ok
|
||||
).exec()
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
|
||||
return True
|
||||
|
||||
@@ -907,7 +908,8 @@ class OfflineModeManager:
|
||||
else:
|
||||
# 恢复UI状态
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
|
||||
return
|
||||
|
||||
@@ -1040,4 +1042,5 @@ class OfflineModeManager:
|
||||
|
||||
# 恢复UI状态
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
@@ -268,7 +268,8 @@ class PatchDetector:
|
||||
QMessageBox.critical(self.main_window, f"文件校验失败 - {APP_NAME}", message)
|
||||
|
||||
self.main_window.setEnabled(True)
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
QTimer.singleShot(100, self.main_window.show_result)
|
||||
|
||||
def on_offline_pre_hash_finished(self, updated_status, game_dirs):
|
||||
@@ -333,7 +334,8 @@ class PatchDetector:
|
||||
"\n未检测到任何需要安装补丁的游戏。\n\n请确保游戏文件夹位于选择的目录中。\n",
|
||||
)
|
||||
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return
|
||||
|
||||
from PySide6 import QtWidgets
|
||||
@@ -367,7 +369,8 @@ class PatchDetector:
|
||||
|
||||
result = dialog.exec()
|
||||
if result != QtWidgets.QDialog.DialogCode.Accepted or not list_widget.selectedItems():
|
||||
self.main_window.ui_manager.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
return
|
||||
|
||||
selected_games = [item.text() for item in list_widget.selectedItems()]
|
||||
|
||||
@@ -383,7 +383,7 @@ class UIManager:
|
||||
if self.ipv6_manager:
|
||||
self.ipv6_test_action.triggered.connect(self.ipv6_manager.show_ipv6_details)
|
||||
else:
|
||||
self.ipv6_test_action.triggered.connect(self.show_ipv6_manager_not_ready)
|
||||
self.ipv6_test_action.triggered.connect(lambda: self._create_message_box("错误", "\nIPv6管理器尚未初始化,请稍后再试。\n").exec())
|
||||
|
||||
# 创建IPv6支持子菜单
|
||||
self.ipv6_submenu = QMenu("IPv6支持", self.main_window)
|
||||
@@ -476,7 +476,7 @@ class UIManager:
|
||||
self.switch_source_action = QAction("修改下载源", self.main_window)
|
||||
self.switch_source_action.setFont(menu_font)
|
||||
self.switch_source_action.setEnabled(True)
|
||||
self.switch_source_action.triggered.connect(self.show_under_development)
|
||||
self.switch_source_action.triggered.connect(lambda: self._create_message_box("提示", "\n该功能正在开发中,敬请期待!\n").exec())
|
||||
|
||||
# 添加下载线程设置选项
|
||||
self.thread_settings_action = QAction("下载线程设置", self.main_window)
|
||||
@@ -638,15 +638,12 @@ class UIManager:
|
||||
|
||||
reply = msg_box.exec()
|
||||
if reply == QMessageBox.StandardButton.Yes:
|
||||
# 用户确认撤回
|
||||
try:
|
||||
# 导入隐私管理器
|
||||
from core.managers.privacy_manager import PrivacyManager
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
# 创建实例并重置隐私协议同意
|
||||
privacy_manager = PrivacyManager()
|
||||
if privacy_manager.reset_privacy_agreement():
|
||||
# 显示重启提示
|
||||
@@ -656,32 +653,21 @@ class UIManager:
|
||||
)
|
||||
restart_msg.exec()
|
||||
|
||||
# 获取当前执行的Python解释器路径和脚本路径
|
||||
# 重启应用程序
|
||||
python_executable = sys.executable
|
||||
script_path = os.path.abspath(sys.argv[0])
|
||||
|
||||
# 构建重启命令
|
||||
restart_cmd = [python_executable, script_path]
|
||||
|
||||
# 启动新进程
|
||||
subprocess.Popen(restart_cmd)
|
||||
|
||||
# 退出当前进程
|
||||
subprocess.Popen([python_executable, script_path])
|
||||
sys.exit(0)
|
||||
else:
|
||||
# 显示失败提示
|
||||
fail_msg = self._create_message_box(
|
||||
self._create_message_box(
|
||||
"操作失败",
|
||||
"\n撤回隐私协议同意失败。\n\n请检查应用权限或稍后再试。\n"
|
||||
)
|
||||
fail_msg.exec()
|
||||
).exec()
|
||||
except Exception as e:
|
||||
# 显示错误提示
|
||||
error_msg = self._create_message_box(
|
||||
self._create_message_box(
|
||||
"错误",
|
||||
f"\n撤回隐私协议同意时发生错误:\n\n{str(e)}\n"
|
||||
)
|
||||
error_msg.exec()
|
||||
).exec()
|
||||
|
||||
def _create_message_box(self, title, message, buttons=QMessageBox.StandardButton.Ok):
|
||||
"""创建统一风格的消息框
|
||||
@@ -701,11 +687,6 @@ class UIManager:
|
||||
)
|
||||
return msg_box
|
||||
|
||||
def show_under_development(self):
|
||||
"""显示功能正在开发中的提示"""
|
||||
msg_box = self._create_message_box("提示", "\n该功能正在开发中,敬请期待!\n")
|
||||
msg_box.exec()
|
||||
|
||||
def show_download_thread_settings(self):
|
||||
"""显示下载线程设置对话框"""
|
||||
if hasattr(self.main_window, 'download_manager'):
|
||||
@@ -1001,10 +982,7 @@ class UIManager:
|
||||
msg_box.setTextFormat(Qt.TextFormat.RichText) # 使用Qt.TextFormat
|
||||
msg_box.exec()
|
||||
|
||||
def show_ipv6_manager_not_ready(self):
|
||||
"""显示IPv6管理器未准备好的提示"""
|
||||
msg_box = self._create_message_box("错误", "\nIPv6管理器尚未初始化,请稍后再试。\n")
|
||||
msg_box.exec()
|
||||
|
||||
|
||||
def switch_work_mode(self, mode):
|
||||
"""切换工作模式
|
||||
@@ -1040,7 +1018,8 @@ class UIManager:
|
||||
self.main_window.save_config(self.main_window.config)
|
||||
|
||||
# 在离线模式下启用开始安装按钮
|
||||
self.set_install_button_state("ready")
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
|
||||
# 清除版本警告标志
|
||||
if hasattr(self.main_window, 'version_warning'):
|
||||
@@ -1141,32 +1120,4 @@ class UIManager:
|
||||
self.loading_dialog.hide()
|
||||
self.loading_dialog = None
|
||||
|
||||
def set_install_button_state(self, state):
|
||||
"""统一的安装按钮状态管理方法
|
||||
|
||||
Args:
|
||||
state (str): 按钮状态 - "ready", "installing", "disabled", "completed"
|
||||
"""
|
||||
if hasattr(self.main_window, 'window_manager'):
|
||||
if state == "ready":
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_READY)
|
||||
elif state == "installing":
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_INSTALLING)
|
||||
elif state == "disabled":
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_ERROR)
|
||||
elif state == "completed":
|
||||
self.main_window.window_manager.change_window_state(self.main_window.window_manager.STATE_COMPLETED)
|
||||
else:
|
||||
# 降级处理,直接设置按钮状态
|
||||
if state == "ready":
|
||||
self.main_window.ui.start_install_btn.setEnabled(True)
|
||||
self.main_window.ui.start_install_text.setText("开始安装")
|
||||
elif state == "installing":
|
||||
self.main_window.ui.start_install_btn.setEnabled(False)
|
||||
self.main_window.ui.start_install_text.setText("正在安装")
|
||||
elif state == "disabled":
|
||||
self.main_window.ui.start_install_btn.setEnabled(False)
|
||||
self.main_window.ui.start_install_text.setText("!无法安装!")
|
||||
elif state == "completed":
|
||||
self.main_window.ui.start_install_btn.setEnabled(True)
|
||||
self.main_window.ui.start_install_text.setText("安装完成")
|
||||
|
||||
Reference in New Issue
Block a user