Tray dark theme (#591)
This commit is contained in:
parent
6231499c39
commit
db1308e3f5
|
|
@ -0,0 +1,35 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def is_windows_dark_theme() -> bool:
|
||||||
|
if sys.platform != "win32":
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
import winreg
|
||||||
|
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize")
|
||||||
|
value, _ = winreg.QueryValueEx(key, "AppsUseLightTheme")
|
||||||
|
return value == 0
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def apply_windows_dark_theme() -> None:
|
||||||
|
try:
|
||||||
|
import ctypes
|
||||||
|
uxtheme = ctypes.windll.uxtheme
|
||||||
|
|
||||||
|
try:
|
||||||
|
set_preferred = uxtheme[135]
|
||||||
|
result = set_preferred(2)
|
||||||
|
if result == 0:
|
||||||
|
flush = uxtheme[136]
|
||||||
|
flush()
|
||||||
|
except Exception:
|
||||||
|
try:
|
||||||
|
allow_dark = uxtheme[135]
|
||||||
|
allow_dark(True)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
@ -32,6 +32,10 @@ except ImportError:
|
||||||
|
|
||||||
import proxy.tg_ws_proxy as tg_ws_proxy
|
import proxy.tg_ws_proxy as tg_ws_proxy
|
||||||
|
|
||||||
|
from utils.win32_theme import (
|
||||||
|
is_windows_dark_theme,
|
||||||
|
apply_windows_dark_theme,
|
||||||
|
)
|
||||||
from utils.tray_common import (
|
from utils.tray_common import (
|
||||||
APP_NAME, DEFAULT_CONFIG, FIRST_RUN_MARKER, IS_FROZEN, LOG_FILE,
|
APP_NAME, DEFAULT_CONFIG, FIRST_RUN_MARKER, IS_FROZEN, LOG_FILE,
|
||||||
acquire_lock, bootstrap, check_ipv6_warning, ctk_run_dialog,
|
acquire_lock, bootstrap, check_ipv6_warning, ctk_run_dialog,
|
||||||
|
|
@ -316,6 +320,10 @@ def run_tray() -> None:
|
||||||
global _tray_icon, _config
|
global _tray_icon, _config
|
||||||
|
|
||||||
_config = load_config()
|
_config = load_config()
|
||||||
|
|
||||||
|
if is_windows_dark_theme:
|
||||||
|
apply_windows_dark_theme()
|
||||||
|
|
||||||
bootstrap(_config)
|
bootstrap(_config)
|
||||||
|
|
||||||
if pystray is None or Image is None or ctk is None:
|
if pystray is None or Image is None or ctk is None:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue