Skip to content

Commit

Permalink
Add theme detect timer implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Loren Eteval <[email protected]>
  • Loading branch information
LorenEteval committed Sep 20, 2023
1 parent 5d12b10 commit 7c74779
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions Furious/Widget/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ServerStorage,
SupportThemeChangedCallback,
NeedSyncSettings,
isScriptMode,
)
from Furious.Utility.Proxy import Proxy
from Furious.Utility.Settings import Settings
Expand Down Expand Up @@ -179,6 +180,8 @@ def __init__(self, argv):
self.logStreamHandle = None

# Theme Detect
self.currentTheme = None
self.themeDetectTimer = None
self.themeDetector = None
self.themeListenerThread = None

Expand Down Expand Up @@ -256,18 +259,6 @@ def initTray(self):
self.addCustomFont()
self.configureLogging()

self.themeDetector = ApplicationThemeDetector()
self.themeDetector.themeChanged.connect(
SupportThemeChangedCallback.callThemeChangedCallback
)

self.themeListenerThread = threading.Thread(
target=darkdetect.listener,
args=(self.themeDetector.themeChanged.emit,),
daemon=True,
)
self.themeListenerThread.start()

import PySide6

logger.info(f'application version: {APPLICATION_VERSION}')
Expand All @@ -282,6 +273,37 @@ def initTray(self):
logger.info(f'system language is {SYSTEM_LANGUAGE}')
logger.info(self.customFontLoadMsg)

if PLATFORM != 'Windows' and not isScriptMode():
logger.info('theme detect method uses timer implementation')

@QtCore.Slot()
def handleTimeout():
currentTheme = darkdetect.theme()

if self.currentTheme != currentTheme:
self.currentTheme = currentTheme

SupportThemeChangedCallback.callThemeChangedCallback(currentTheme)

self.currentTheme = darkdetect.theme()
self.themeDetectTimer = QtCore.QTimer()
self.themeDetectTimer.timeout.connect(handleTimeout)
self.themeDetectTimer.start(1)
else:
logger.info('theme detect method uses listener implementation')

self.themeDetector = ApplicationThemeDetector()
self.themeDetector.themeChanged.connect(
SupportThemeChangedCallback.callThemeChangedCallback
)

self.themeListenerThread = threading.Thread(
target=darkdetect.listener,
args=(self.themeDetector.themeChanged.emit,),
daemon=True,
)
self.themeListenerThread.start()

# Mandatory
self.setQuitOnLastWindowClosed(False)

Expand Down

0 comments on commit 7c74779

Please sign in to comment.