mirror of
https://github.com/Syncplay/syncplay
synced 2025-03-31 15:48:53 +00:00
darkdetect: update vendor copy to 0.5.0
This commit is contained in:
parent
0b8c2ddc4b
commit
16168effc4
syncplay/vendor/darkdetect
20
syncplay/vendor/darkdetect/__init__.py
vendored
Executable file → Normal file
20
syncplay/vendor/darkdetect/__init__.py
vendored
Executable file → Normal file
@ -4,19 +4,29 @@
|
||||
# Distributed under the terms of the 3-clause BSD License.
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
__version__ = '0.1.1'
|
||||
__version__ = '0.5.0'
|
||||
|
||||
import sys
|
||||
import platform
|
||||
|
||||
if sys.platform != "darwin":
|
||||
from ._dummy import *
|
||||
else:
|
||||
if sys.platform == "darwin":
|
||||
from distutils.version import LooseVersion as V
|
||||
if V(platform.mac_ver()[0]) < V("10.14"):
|
||||
from ._dummy import *
|
||||
else:
|
||||
from ._detect import *
|
||||
from ._mac_detect import *
|
||||
del V
|
||||
elif sys.platform == "win32" and platform.release() == "10":
|
||||
# Checks if running Windows 10 version 10.0.14393 (Anniversary Update) or higher. The getwindowsversion method returns a tuple.
|
||||
# The third item is the build number that we can use to check if the user has a new enough version of Windows.
|
||||
winver = int(sys.getwindowsversion()[2])
|
||||
if winver >= 14393:
|
||||
from ._windows_detect import *
|
||||
else:
|
||||
from ._dummy import *
|
||||
elif sys.platform == "linux":
|
||||
from ._linux_detect import *
|
||||
else:
|
||||
from ._dummy import *
|
||||
|
||||
del sys, platform
|
0
syncplay/vendor/darkdetect/_dummy.py
vendored
Executable file → Normal file
0
syncplay/vendor/darkdetect/_dummy.py
vendored
Executable file → Normal file
30
syncplay/vendor/darkdetect/_linux_detect.py
vendored
Normal file
30
syncplay/vendor/darkdetect/_linux_detect.py
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
# Copyright (C) 2019 Alberto Sottile, Eric Larson
|
||||
#
|
||||
# Distributed under the terms of the 3-clause BSD License.
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
import subprocess
|
||||
|
||||
|
||||
def theme():
|
||||
# Here we just triage to GTK settings for now
|
||||
try:
|
||||
out = subprocess.run(
|
||||
['gsettings', 'get', 'org.gnome.desktop.interface', 'gtk-theme'],
|
||||
capture_output=True)
|
||||
stdout = out.stdout.decode()
|
||||
except Exception:
|
||||
return 'Light'
|
||||
# we have a string, now remove start and end quote
|
||||
theme = stdout.lower().strip()[1:-1]
|
||||
if theme.endswith('-dark'):
|
||||
return 'Dark'
|
||||
else:
|
||||
return 'Light'
|
||||
|
||||
def isDark():
|
||||
return theme() == 'Dark'
|
||||
|
||||
def isLight():
|
||||
return theme() == 'Light'
|
18
syncplay/vendor/darkdetect/_detect.py → syncplay/vendor/darkdetect/_mac_detect.py
vendored
Executable file → Normal file
18
syncplay/vendor/darkdetect/_detect.py → syncplay/vendor/darkdetect/_mac_detect.py
vendored
Executable file → Normal file
@ -6,19 +6,27 @@
|
||||
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
import platform
|
||||
|
||||
appkit = ctypes.cdll.LoadLibrary(ctypes.util.find_library('AppKit'))
|
||||
objc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('objc'))
|
||||
from distutils.version import LooseVersion as V
|
||||
|
||||
if V(platform.mac_ver()[0]) < V("10.16"):
|
||||
appkit = ctypes.cdll.LoadLibrary(ctypes.util.find_library('AppKit'))
|
||||
objc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('objc'))
|
||||
else:
|
||||
appkit = ctypes.cdll.LoadLibrary('AppKit.framework/AppKit')
|
||||
objc = ctypes.cdll.LoadLibrary('libobjc.dylib')
|
||||
del V
|
||||
|
||||
void_p = ctypes.c_void_p
|
||||
ull = ctypes.c_uint64
|
||||
|
||||
objc.objc_getClass.restype = void_p
|
||||
objc.sel_registerName.restype = void_p
|
||||
objc.objc_msgSend.restype = void_p
|
||||
objc.objc_msgSend.argtypes = [void_p, void_p]
|
||||
|
||||
msg = objc.objc_msgSend
|
||||
# See https://docs.python.org/3/library/ctypes.html#function-prototypes for arguments description
|
||||
MSGPROTOTYPE = ctypes.CFUNCTYPE(void_p, void_p, void_p, void_p)
|
||||
msg = MSGPROTOTYPE(('objc_msgSend', objc), ((1 ,'', None), (1, '', None), (1, '', None)))
|
||||
|
||||
def _utf8(s):
|
||||
if not isinstance(s, bytes):
|
18
syncplay/vendor/darkdetect/_windows_detect.py
vendored
Normal file
18
syncplay/vendor/darkdetect/_windows_detect.py
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
from winreg import HKEY_CURRENT_USER as hkey, QueryValueEx as getSubkeyValue, OpenKey as getKey
|
||||
|
||||
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.
|
||||
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]
|
||||
return valueMeaning[subkey]
|
||||
|
||||
def isDark():
|
||||
return theme() == 'Dark'
|
||||
|
||||
def isLight():
|
||||
return theme() == 'Light'
|
Loading…
Reference in New Issue
Block a user