mirror of
https://github.com/hyb-oyqq/FRAISEMOE-Addons-Installer-NEXT.git
synced 2025-12-15 19:30:28 +00:00
feat(core): 增强工作模式菜单状态同步功能
- 在主窗口和离线模式管理器中添加工作模式菜单状态同步逻辑,确保UI状态与实际工作模式一致。 - 在UI管理器中实现同步方法,提升菜单状态更新的可靠性和兼容性。 - 优化代码结构,确保在菜单创建后立即同步状态,增强用户体验。
This commit is contained in:
@@ -204,9 +204,14 @@ class OfflineModeManager:
|
||||
# 同步更新UI菜单中的模式选择状态
|
||||
if hasattr(self.main_window, 'ui_manager'):
|
||||
ui_manager = self.main_window.ui_manager
|
||||
if hasattr(ui_manager, 'online_mode_action') and hasattr(ui_manager, 'offline_mode_action'):
|
||||
ui_manager.online_mode_action.setChecked(not enabled)
|
||||
ui_manager.offline_mode_action.setChecked(enabled)
|
||||
# 使用专门的同步方法确保菜单状态正确更新
|
||||
if hasattr(ui_manager, 'sync_work_mode_menu_state'):
|
||||
ui_manager.sync_work_mode_menu_state()
|
||||
elif hasattr(ui_manager, 'online_mode_action') and hasattr(ui_manager, 'offline_mode_action'):
|
||||
# 兼容旧版本的直接设置方式
|
||||
if ui_manager.online_mode_action and ui_manager.offline_mode_action:
|
||||
ui_manager.online_mode_action.setChecked(not enabled)
|
||||
ui_manager.offline_mode_action.setChecked(enabled)
|
||||
|
||||
# 记录离线模式状态变化
|
||||
logger.debug(f"离线模式已{'启用' if enabled else '禁用'}")
|
||||
|
||||
@@ -63,6 +63,13 @@ class UIManager:
|
||||
self.disable_auto_restore_action = self.menu_builder.disable_auto_restore_action
|
||||
self.disable_pre_hash_action = self.menu_builder.disable_pre_hash_action
|
||||
|
||||
# 保存对工作模式菜单项的引用,确保能正确同步状态
|
||||
self.online_mode_action = self.menu_builder.online_mode_action
|
||||
self.offline_mode_action = self.menu_builder.offline_mode_action
|
||||
|
||||
# 在菜单创建完成后,强制同步一次工作模式状态
|
||||
self.sync_work_mode_menu_state()
|
||||
|
||||
# 为了向后兼容性,添加委托方法
|
||||
def create_progress_window(self, title, initial_text="准备中..."):
|
||||
"""创建进度窗口(委托给dialog_factory)"""
|
||||
@@ -84,6 +91,39 @@ class UIManager:
|
||||
"""显示菜单(委托给menu_builder)"""
|
||||
return self.menu_builder.show_menu(menu, button)
|
||||
|
||||
def sync_work_mode_menu_state(self):
|
||||
"""同步工作模式菜单状态,确保菜单选择状态与实际工作模式一致"""
|
||||
try:
|
||||
# 检查是否有离线模式管理器和菜单项
|
||||
if not hasattr(self.main_window, 'offline_mode_manager') or not self.main_window.offline_mode_manager:
|
||||
return
|
||||
|
||||
if not hasattr(self, 'online_mode_action') or not hasattr(self, 'offline_mode_action'):
|
||||
return
|
||||
|
||||
if not self.online_mode_action or not self.offline_mode_action:
|
||||
return
|
||||
|
||||
# 获取当前离线模式状态
|
||||
is_offline_mode = self.main_window.offline_mode_manager.is_in_offline_mode()
|
||||
|
||||
# 同步菜单选择状态
|
||||
self.online_mode_action.setChecked(not is_offline_mode)
|
||||
self.offline_mode_action.setChecked(is_offline_mode)
|
||||
|
||||
# 记录同步操作(仅在调试模式下)
|
||||
if hasattr(self.main_window, 'config') and self.main_window.config.get('debug_mode', False):
|
||||
from utils.logger import setup_logger
|
||||
logger = setup_logger("ui_manager")
|
||||
logger.debug(f"已同步工作模式菜单状态: 离线模式={is_offline_mode}")
|
||||
|
||||
except Exception as e:
|
||||
# 静默处理异常,避免影响程序正常运行
|
||||
if hasattr(self.main_window, 'config') and self.main_window.config.get('debug_mode', False):
|
||||
from utils.logger import setup_logger
|
||||
logger = setup_logger("ui_manager")
|
||||
logger.debug(f"同步工作模式菜单状态时出错: {e}")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -207,6 +207,10 @@ class MainWindow(QMainWindow):
|
||||
else:
|
||||
self.window_manager.change_window_state(self.window_manager.STATE_ERROR)
|
||||
|
||||
# 确保工作模式菜单状态与实际状态同步
|
||||
if hasattr(self, 'ui_manager') and hasattr(self.ui_manager, 'sync_work_mode_menu_state'):
|
||||
self.ui_manager.sync_work_mode_menu_state()
|
||||
|
||||
def set_start_button_enabled(self, enabled, installing=False):
|
||||
"""[过渡方法] 设置按钮状态,将调用委托给WindowManager
|
||||
|
||||
|
||||
Reference in New Issue
Block a user