mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
dark
This commit is contained in:
parent
21aa04382e
commit
d9c80e5761
@ -1,88 +0,0 @@
|
|||||||
from winreg import (
|
|
||||||
HKEY_CURRENT_USER as hkey,
|
|
||||||
QueryValueEx as getSubkeyValue,
|
|
||||||
OpenKey as getKey,
|
|
||||||
)
|
|
||||||
|
|
||||||
import ctypes
|
|
||||||
import ctypes.wintypes
|
|
||||||
|
|
||||||
advapi32 = ctypes.windll.advapi32
|
|
||||||
|
|
||||||
# LSTATUS RegOpenKeyExA(
|
|
||||||
# HKEY hKey,
|
|
||||||
# LPCSTR lpSubKey,
|
|
||||||
# DWORD ulOptions,
|
|
||||||
# REGSAM samDesired,
|
|
||||||
# PHKEY phkResult
|
|
||||||
# );
|
|
||||||
advapi32.RegOpenKeyExA.argtypes = (
|
|
||||||
ctypes.wintypes.HKEY,
|
|
||||||
ctypes.wintypes.LPCSTR,
|
|
||||||
ctypes.wintypes.DWORD,
|
|
||||||
ctypes.wintypes.DWORD,
|
|
||||||
ctypes.POINTER(ctypes.wintypes.HKEY),
|
|
||||||
)
|
|
||||||
advapi32.RegOpenKeyExA.restype = ctypes.wintypes.LONG
|
|
||||||
|
|
||||||
# LSTATUS RegQueryValueExA(
|
|
||||||
# HKEY hKey,
|
|
||||||
# LPCSTR lpValueName,
|
|
||||||
# LPDWORD lpReserved,
|
|
||||||
# LPDWORD lpType,
|
|
||||||
# LPBYTE lpData,
|
|
||||||
# LPDWORD lpcbData
|
|
||||||
# );
|
|
||||||
advapi32.RegQueryValueExA.argtypes = (
|
|
||||||
ctypes.wintypes.HKEY,
|
|
||||||
ctypes.wintypes.LPCSTR,
|
|
||||||
ctypes.wintypes.LPDWORD,
|
|
||||||
ctypes.wintypes.LPDWORD,
|
|
||||||
ctypes.wintypes.LPBYTE,
|
|
||||||
ctypes.wintypes.LPDWORD,
|
|
||||||
)
|
|
||||||
advapi32.RegQueryValueExA.restype = ctypes.wintypes.LONG
|
|
||||||
|
|
||||||
# LSTATUS RegNotifyChangeKeyValue(
|
|
||||||
# HKEY hKey,
|
|
||||||
# WINBOOL bWatchSubtree,
|
|
||||||
# DWORD dwNotifyFilter,
|
|
||||||
# HANDLE hEvent,
|
|
||||||
# WINBOOL fAsynchronous
|
|
||||||
# );
|
|
||||||
advapi32.RegNotifyChangeKeyValue.argtypes = (
|
|
||||||
ctypes.wintypes.HKEY,
|
|
||||||
ctypes.wintypes.BOOL,
|
|
||||||
ctypes.wintypes.DWORD,
|
|
||||||
ctypes.wintypes.HANDLE,
|
|
||||||
ctypes.wintypes.BOOL,
|
|
||||||
)
|
|
||||||
advapi32.RegNotifyChangeKeyValue.restype = ctypes.wintypes.LONG
|
|
||||||
|
|
||||||
|
|
||||||
def theme():
|
|
||||||
"""Uses the Windows Registry to detect if the user is using Dark Mode"""
|
|
||||||
# Registry will return 0 if Windows is in Dark Mode and 1 if Windows is in Light Mode. This dictionary converts that output into the text that the program is expecting.
|
|
||||||
valueMeaning = {0: "Dark", 1: "Light"}
|
|
||||||
# In HKEY_CURRENT_USER, get the Personalisation Key.
|
|
||||||
try:
|
|
||||||
key = getKey(
|
|
||||||
hkey, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"
|
|
||||||
)
|
|
||||||
# In the Personalisation Key, get the AppsUseLightTheme subkey. This returns a tuple.
|
|
||||||
# The first item in the tuple is the result we want (0 or 1 indicating Dark Mode or Light Mode); the other value is the type of subkey e.g. DWORD, QWORD, String, etc.
|
|
||||||
subkey = getSubkeyValue(key, "AppsUseLightTheme")[0]
|
|
||||||
except FileNotFoundError:
|
|
||||||
# some headless Windows instances (e.g. GitHub Actions or Docker images) do not have this key
|
|
||||||
return None
|
|
||||||
return valueMeaning[subkey]
|
|
||||||
|
|
||||||
|
|
||||||
def isDark():
|
|
||||||
if theme() is not None:
|
|
||||||
return theme() == "Dark"
|
|
||||||
|
|
||||||
|
|
||||||
def isLight():
|
|
||||||
if theme() is not None:
|
|
||||||
return theme() == "Light"
|
|
@ -17,6 +17,7 @@ from PyQt5.QtWidgets import QTabWidget
|
|||||||
import qtawesome, darkdetect, gobject
|
import qtawesome, darkdetect, gobject
|
||||||
import functools, threading, windows, os, winsharedutils
|
import functools, threading, windows, os, winsharedutils
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
|
from winsharedutils import isDark
|
||||||
from myutils.config import globalconfig, _TR
|
from myutils.config import globalconfig, _TR
|
||||||
from myutils.utils import wavmp3player
|
from myutils.utils import wavmp3player
|
||||||
from myutils.config import static_data
|
from myutils.config import static_data
|
||||||
@ -253,9 +254,7 @@ class Settin(closeashidewindow):
|
|||||||
elif dl == 1:
|
elif dl == 1:
|
||||||
dark = True
|
dark = True
|
||||||
elif dl == 2:
|
elif dl == 2:
|
||||||
dark = darkdetect.isDark()
|
dark = isDark()
|
||||||
if dark is None:
|
|
||||||
dark = False
|
|
||||||
darklight = ["light", "dark"][dark]
|
darklight = ["light", "dark"][dark]
|
||||||
|
|
||||||
class WindowEventFilter(QObject):
|
class WindowEventFilter(QObject):
|
||||||
|
@ -344,3 +344,6 @@ getpidhwndfirst.restype = HWND
|
|||||||
Is64bit = utilsdll.Is64bit
|
Is64bit = utilsdll.Is64bit
|
||||||
Is64bit.argtypes = (DWORD,)
|
Is64bit.argtypes = (DWORD,)
|
||||||
Is64bit.restype = c_bool
|
Is64bit.restype = c_bool
|
||||||
|
|
||||||
|
isDark = utilsdll.isDark
|
||||||
|
isDark.restype = c_bool
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <dwmapi.h>
|
#include <dwmapi.h>
|
||||||
|
#include <string>
|
||||||
#include "define.h"
|
#include "define.h"
|
||||||
// https://github.com/Blinue/Xaml-Islands-Cpp/blob/main/src/XamlIslandsCpp/XamlWindow.h
|
// https://github.com/Blinue/Xaml-Islands-Cpp/blob/main/src/XamlIslandsCpp/XamlWindow.h
|
||||||
|
|
||||||
@ -171,3 +172,21 @@ bool _SetTheme(
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DECLARE bool isDark()
|
||||||
|
{
|
||||||
|
HKEY hKey;
|
||||||
|
const char *subKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
|
||||||
|
if (RegOpenKeyExA(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
DWORD value;
|
||||||
|
DWORD dataSize = sizeof(DWORD);
|
||||||
|
if (RegQueryValueExA(hKey, "AppsUseLightTheme", 0, NULL, (LPBYTE)&value, &dataSize) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return 1 - value;
|
||||||
|
}
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user