diff --git a/syncplay/vendor/darkdetect/__init__.py b/syncplay/vendor/darkdetect/__init__.py old mode 100755 new mode 100644 index 4cce200..bb1df11 --- a/syncplay/vendor/darkdetect/__init__.py +++ b/syncplay/vendor/darkdetect/__init__.py @@ -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 \ No newline at end of file diff --git a/syncplay/vendor/darkdetect/_dummy.py b/syncplay/vendor/darkdetect/_dummy.py old mode 100755 new mode 100644 diff --git a/syncplay/vendor/darkdetect/_linux_detect.py b/syncplay/vendor/darkdetect/_linux_detect.py new file mode 100644 index 0000000..3110ae8 --- /dev/null +++ b/syncplay/vendor/darkdetect/_linux_detect.py @@ -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' diff --git a/syncplay/vendor/darkdetect/_detect.py b/syncplay/vendor/darkdetect/_mac_detect.py old mode 100755 new mode 100644 similarity index 69% rename from syncplay/vendor/darkdetect/_detect.py rename to syncplay/vendor/darkdetect/_mac_detect.py index 9a79f7c..322582f --- a/syncplay/vendor/darkdetect/_detect.py +++ b/syncplay/vendor/darkdetect/_mac_detect.py @@ -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): diff --git a/syncplay/vendor/darkdetect/_windows_detect.py b/syncplay/vendor/darkdetect/_windows_detect.py new file mode 100644 index 0000000..61409a7 --- /dev/null +++ b/syncplay/vendor/darkdetect/_windows_detect.py @@ -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' \ No newline at end of file