Fix theme detection

Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
Loren Eteval
2025-12-15 13:34:37 +08:00
parent 9a9b17ac31
commit 438cae1dfc
4 changed files with 22 additions and 20 deletions
+1 -2
View File
@@ -23,7 +23,6 @@ from PySide6.QtGui import *
import logging
import functools
import darkdetect
logger = logging.getLogger(__name__)
@@ -198,7 +197,7 @@ class AppQAction(Mixins.QTranslatable, Mixins.ThemeAware, QAction):
# Fall back
super().setIcon(icon)
else:
self.setIconByTheme(darkdetect.theme())
self.setIconByTheme(APP().theme())
def themeChangedCallback(self, theme):
self.setIconByTheme(theme)
+15 -10
View File
@@ -285,13 +285,18 @@ class Application(ApplicationFactory, SingletonApplication):
return backgroudColor.lightness() < 128
def isDarkModeEnabled(self):
if SystemRuntime.flatpakID():
return self.isDarkMode()
# if SystemRuntime.flatpakID():
# return self.isDarkMode()
#
# if not SystemRuntime.isAdmin():
# return AppSettings.isStateON_('DarkMode')
# else:
# return self.isDarkMode()
if not SystemRuntime.isAdmin():
return AppSettings.isStateON_('DarkMode')
else:
return self.isDarkMode()
return AppSettings.isStateON_('DarkMode')
def theme(self):
return 'Dark' if self.isDarkMode() else 'Light'
def switchToDarkMode(self):
self.setStyleSheet(qdarkstyle.load_stylesheet_pyside6())
@@ -301,7 +306,7 @@ class Application(ApplicationFactory, SingletonApplication):
def switchToAutoMode(self):
self.setStyleSheet('')
Mixins.ThemeAware.callThemeChangedCallbackUnchecked(darkdetect.theme())
Mixins.ThemeAware.callThemeChangedCallbackUnchecked(self.theme())
@staticmethod
@callOnceOnly
@@ -416,21 +421,21 @@ class Application(ApplicationFactory, SingletonApplication):
logger.info(f'isPythonw: {SystemRuntime.isPythonw()}')
logger.info(f'system language is {SYSTEM_LANGUAGE}')
logger.info(self.customFontLoadMsg)
logger.info(f'current theme is {darkdetect.theme()}')
logger.info(f'current theme is {self.theme()}')
if PLATFORM != 'Windows' and not SystemRuntime.isScriptMode():
logger.info('theme detect method uses timer implementation')
@QtCore.Slot()
def handleTimeout():
currentTheme = darkdetect.theme()
currentTheme = self.theme()
if self.currentTheme != currentTheme:
self.currentTheme = currentTheme
Mixins.ThemeAware.callThemeChangedCallback(currentTheme)
self.currentTheme = darkdetect.theme()
self.currentTheme = self.theme()
self.themeDetectTimer = QtCore.QTimer()
self.themeDetectTimer.timeout.connect(handleTimeout)
self.themeDetectTimer.start(1000)
+4 -5
View File
@@ -25,7 +25,6 @@ from PySide6.QtWidgets import QSystemTrayIcon
import logging
import platform
import darkdetect
logger = logging.getLogger(__name__)
@@ -143,7 +142,7 @@ class SystemTrayIcon(
switchMonochrome()
def setMonochromeIcon(self):
self.setMonochromeIconByTheme(darkdetect.theme())
self.setMonochromeIconByTheme(APP().theme())
def setDisconnectedIcon(self):
if AppSettings.isStateON_('UseMonochromeTrayIcon'):
@@ -154,7 +153,7 @@ class SystemTrayIcon(
if (
PLATFORM == 'Darwin'
or SystemRuntime.isWindows7()
or (PLATFORM == 'Windows' and darkdetect.theme() == 'Light')
or (PLATFORM == 'Windows' and APP().theme() == 'Light')
):
# Darker
self.setIcon(bootstrapIcon('rocket-takeoff-dark.svg'))
@@ -173,7 +172,7 @@ class SystemTrayIcon(
if (
PLATFORM == 'Darwin'
or SystemRuntime.isWindows7()
or (PLATFORM == 'Windows' and darkdetect.theme() == 'Light')
or (PLATFORM == 'Windows' and APP().theme() == 'Light')
):
# Darker
self.setIcon(bootstrapIcon('rocket-takeoff-connected-dark.svg'))
@@ -202,7 +201,7 @@ class SystemTrayIcon(
def themeChangedCallback(self, theme):
if AppSettings.isStateON_('UseMonochromeTrayIcon'):
# 'theme' is not used. Instead, always query current theme
self.setMonochromeIconByTheme(darkdetect.theme())
self.setMonochromeIconByTheme(APP().theme())
return
+2 -3
View File
@@ -30,7 +30,6 @@ import shutil
import logging
import datetime
import functools
import darkdetect
__all__ = ['XrayAssetViewerQListWidget']
@@ -65,7 +64,7 @@ class XrayAssetViewerQListWidget(Mixins.ThemeAware, AppQListWidget):
self.setIconSize(QtCore.QSize(64, 64))
if PLATFORM == 'Linux' and SystemRuntime.ubuntuRelease() == '20.04':
self.initialTheme = darkdetect.theme()
self.initialTheme = APP().theme()
else:
self.initialTheme = None
@@ -148,7 +147,7 @@ class XrayAssetViewerQListWidget(Mixins.ThemeAware, AppQListWidget):
# Ubuntu 20.04. Flush by initial theme(Ubuntu 20.04 theme changes bug)
self.flushItemByTheme(self.initialTheme)
else:
self.flushItemByTheme(darkdetect.theme())
self.flushItemByTheme(APP().theme())
def appendNewItem(self, filename: str):
def append(_filename):