mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
cache dark mode value so UI doesn't break when it changes
https://anki.tenderapp.com/discussions/ankidesktop/39550-cant-deactivate-night-mode-on-2121-for-mac
This commit is contained in:
parent
7a4f3d0318
commit
7d94465256
1 changed files with 8 additions and 3 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
from typing import Dict
|
from typing import Dict, Optional
|
||||||
|
|
||||||
from anki.utils import isMac
|
from anki.utils import isMac
|
||||||
from aqt import QApplication, gui_hooks, isWin
|
from aqt import QApplication, gui_hooks, isWin
|
||||||
|
@ -17,6 +17,7 @@ class ThemeManager:
|
||||||
_icon_cache_light: Dict[str, QIcon] = {}
|
_icon_cache_light: Dict[str, QIcon] = {}
|
||||||
_icon_cache_dark: Dict[str, QIcon] = {}
|
_icon_cache_dark: Dict[str, QIcon] = {}
|
||||||
_icon_size = 128
|
_icon_size = 128
|
||||||
|
_macos_dark_mode_cached: Optional[bool] = None
|
||||||
|
|
||||||
def macos_dark_mode(self) -> bool:
|
def macos_dark_mode(self) -> bool:
|
||||||
if not getattr(sys, "frozen", False):
|
if not getattr(sys, "frozen", False):
|
||||||
|
@ -25,9 +26,13 @@ class ThemeManager:
|
||||||
return False
|
return False
|
||||||
if qtminor < 13:
|
if qtminor < 13:
|
||||||
return False
|
return False
|
||||||
|
if self._macos_dark_mode_cached is None:
|
||||||
import darkdetect # pylint: disable=import-error
|
import darkdetect # pylint: disable=import-error
|
||||||
|
|
||||||
return darkdetect.isDark() is True
|
# cache the value, as the interface gets messed up
|
||||||
|
# if the value changes after starting Anki
|
||||||
|
self._macos_dark_mode_cached = darkdetect.isDark() is True
|
||||||
|
return self._macos_dark_mode_cached
|
||||||
|
|
||||||
def get_night_mode(self) -> bool:
|
def get_night_mode(self) -> bool:
|
||||||
return self.macos_dark_mode() or self._night_mode_preference
|
return self.macos_dark_mode() or self._night_mode_preference
|
||||||
|
|
Loading…
Reference in a new issue