Skip to content

The only downloader you need. 下载器的集大成者。

refactor(main_window): 优化主题颜色同步和事件处理逻辑

XiaoYouChR35183bf86a01
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.py
index 9320b5fb..ff1ec382 100644
--- a/Ghost-Downloader-3.py
+++ b/Ghost-Downloader-3.py
@@ -51,6 +51,7 @@ mainWindow = MainWindow(isSilently)
featureService.loadFeatures(mainWindow)
taskRecorder.load()
mainWindow.taskPage.resumeMemorizedTasks()
+mainWindow.syncThemeColor()
if not isSilently:
mainWindow.splashScreen.finish()
diff --git a/app/view/windows/main_window.py b/app/view/windows/main_window.py
index dc6b8cc0..bca85373 100644
--- a/app/view/windows/main_window.py
+++ b/app/view/windows/main_window.py
@@ -9,7 +9,7 @@ from PySide6.QtGui import QDesktopServices, QIcon, QColor, QPalette
from PySide6.QtWidgets import QApplication, QGraphicsOpacityEffect, QDialog
from loguru import logger
from qfluentwidgets import MSFluentWindow, SplashScreen, FluentIcon, NavigationItemPosition, InfoBar, InfoBarPosition, \
- PushButton, PrimaryPushButton, setTheme, Theme, isDarkTheme, setThemeColor, qconfig
+ PushButton, PrimaryPushButton, setTheme, Theme, isDarkTheme, setThemeColor
from app.services.browser_service import BrowserService
from app.services.core_service import coreService
@@ -31,13 +31,6 @@ if TYPE_CHECKING:
from PySide6.QtGui import QClipboard
-BACKGROUND_EFFECT_REFRESH_EVENTS = {
- QEvent.Type.PaletteChange,
- QEvent.Type.StyleChange,
- QEvent.Type.ThemeChange
-}
-
-
class CustomSplashScreen(SplashScreen):
def finish(self):
@@ -74,7 +67,7 @@ class MainWindow(MSFluentWindow):
self.connectSignalToSlot()
self._syncClipboardListener()
self._onThemeChanged(cfg.customThemeMode.value)
- self._syncThemeColor()
+ self.syncThemeColor()
if platform == 'win32':
self._applyBackgroundEffectByCfg(cfg.backgroundEffect.value)
@@ -121,17 +114,18 @@ class MainWindow(MSFluentWindow):
return QColor(0, 0, 0, 0)
- def _syncThemeColor(self):
- palette = self.palette()
+ @staticmethod
+ def syncThemeColor():
+ palette = QApplication.palette()
for role in (QPalette.ColorRole.Accent, QPalette.ColorRole.Highlight):
color = palette.color(role)
- if not color.isValid() or qconfig.themeColor.value == color:
+ if not color.isValid() or cfg.themeColor.value == color:
continue
setThemeColor(color, save=False)
return
-
+
def _applyBackgroundEffectByCfg(self, value: "Literal['Acrylic', 'Mica', 'MicaBlur', 'MicaAlt', 'Aero', 'None']"):
if platform == 'win32':
self.windowEffect.removeBackgroundEffect(self.winId())
@@ -163,7 +157,7 @@ class MainWindow(MSFluentWindow):
self.titleBar.closeBtn.show()
self.titleBar.minBtn.show()
self.titleBar.maxBtn.show()
-
+
def _toggleTheme(self, callback: str):
if callback == 'Dark':
setTheme(Theme.DARK, save=False)
@@ -184,17 +178,12 @@ class MainWindow(MSFluentWindow):
def changeEvent(self, event):
super().changeEvent(event)
- if event.type() in BACKGROUND_EFFECT_REFRESH_EVENTS:
- self._syncThemeColor()
-
- if not self._pendingBackgroundEffectRefresh:
- return
+ if event.type() == QEvent.Type.PaletteChange:
+ self.syncThemeColor()
- if event.type() not in BACKGROUND_EFFECT_REFRESH_EVENTS:
- return
-
- self._pendingBackgroundEffectRefresh = False
- self._applyBackgroundEffectByCfg(cfg.backgroundEffect.value)
+ if self._pendingBackgroundEffectRefresh and event.type() == QEvent.Type.ThemeChange:
+ self._pendingBackgroundEffectRefresh = False
+ self._applyBackgroundEffectByCfg(cfg.backgroundEffect.value)
def _syncClipboardListener(self):
if self.clipboard is None: