fix(ui): 适配深色模式

This commit is contained in:
DLmaster
2025-02-15 17:28:54 +08:00
parent ddf905cb13
commit 284c41feb7
2 changed files with 26 additions and 3 deletions

View File

@@ -36,13 +36,15 @@ from qfluentwidgets import (
InfoBar, InfoBar,
InfoBarPosition, InfoBarPosition,
setTheme, setTheme,
isDarkTheme,
SystemThemeListener,
Theme, Theme,
MSFluentWindow, MSFluentWindow,
NavigationItemPosition, NavigationItemPosition,
qconfig, qconfig,
) )
from PySide6.QtGui import QIcon, QCloseEvent from PySide6.QtGui import QIcon, QCloseEvent
from PySide6.QtCore import Qt from PySide6.QtCore import Qt, QTimer
from app.core import Config, TaskManager, MainTimer, MainInfoBar from app.core import Config, TaskManager, MainTimer, MainInfoBar
from app.services import Notify, Crypto, System from app.services import Notify, Crypto, System
@@ -60,7 +62,7 @@ class AUTO_MAA(MSFluentWindow):
self.setWindowIcon(QIcon(str(Config.app_path / "resources/icons/AUTO_MAA.ico"))) self.setWindowIcon(QIcon(str(Config.app_path / "resources/icons/AUTO_MAA.ico")))
self.setWindowTitle("AUTO_MAA") self.setWindowTitle("AUTO_MAA")
setTheme(Theme.AUTO) setTheme(Theme.AUTO, lazy=True)
self.splashScreen = SplashScreen(self.windowIcon(), self) self.splashScreen = SplashScreen(self.windowIcon(), self)
self.show_ui("显示主窗口", if_quick=True) self.show_ui("显示主窗口", if_quick=True)
@@ -175,6 +177,23 @@ class AUTO_MAA(MSFluentWindow):
self.splashScreen.finish() self.splashScreen.finish()
self.themeListener = SystemThemeListener(self)
self.themeListener.systemThemeChanged.connect(self.switch_theme)
self.themeListener.start()
def switch_theme(self):
"""切换主题"""
setTheme(Theme.AUTO, lazy=True)
QTimer.singleShot(100, lambda: setTheme(Theme.AUTO, lazy=True))
# 云母特效启用时需要增加重试机制
if self.isMicaEffectEnabled():
QTimer.singleShot(
100,
lambda: self.windowEffect.setMicaEffect(self.winId(), isDarkTheme()),
)
def start_up_task(self) -> None: def start_up_task(self) -> None:
"""启动时任务""" """启动时任务"""
@@ -334,6 +353,10 @@ class AUTO_MAA(MSFluentWindow):
# 关闭数据库连接 # 关闭数据库连接
Config.close_database() Config.close_database()
# 关闭主题监听
self.themeListener.terminate()
self.themeListener.deleteLater()
logger.info("AUTO_MAA主程序关闭") logger.info("AUTO_MAA主程序关闭")
logger.info("----------------END----------------") logger.info("----------------END----------------")

View File

@@ -1,7 +1,7 @@
{ {
"main_version": "4.2.3.1", "main_version": "4.2.3.1",
"updater_version": "1.1.1.3", "updater_version": "1.1.1.3",
"announcement": "\n## 新增功能\n- 添加`简洁用户列表下相邻两个任务间的切换方式`可选项\n## 修复BUG\n- 修复静默代理标记移除异常情况\n## 程序优化\n- 优化MAA关闭方法\n- 添加高级代理文件校验过程\n- 升级日志监看方法\n- 优化主调度台默认选项", "announcement": "\n## 新增功能\n- 添加`简洁用户列表下相邻两个任务间的切换方式`可选项\n## 修复BUG\n- 修复静默代理标记移除异常情况\n- 适配深色模式 #18\n## 程序优化\n- 优化MAA关闭方法\n- 添加高级代理文件校验过程\n- 升级日志监看方法\n- 优化主调度台默认选项",
"proxy_list": [ "proxy_list": [
"", "",
"https://gitproxy.click/", "https://gitproxy.click/",