Skip to content

Commit

Permalink
Merge branch 'master' into print_unknown_connection_errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Et0h authored Jan 1, 2023
2 parents 0149932 + 0c8c865 commit 034c7cc
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
python3 --version
which pip3
pip3 --version
file python3
file $(which python3)
- name: Install Python dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion syncplay/players/basePlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def askForStatus(self):
Display given message on player's OSD or similar means
'''
def displayMessage(
self, message, duration=(constants.OSD_DURATION*1000), secondaryOSD=False, mood=constants.MESSAGE_NEUTRAL
self, message, duration=(constants.OSD_DURATION*1000), OSDType=constants.OSD_NOTIFICATION, mood=constants.MESSAGE_NEUTRAL
):
raise NotImplementedError()

Expand Down
28 changes: 20 additions & 8 deletions syncplay/vendor/darkdetect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@
# Distributed under the terms of the 3-clause BSD License.
#-----------------------------------------------------------------------------

__version__ = '0.5.2'
__version__ = '0.7.1'

import sys
import platform

if sys.platform == "darwin":
from distutils.version import LooseVersion as V
if V(platform.mac_ver()[0]) < V("10.14"):
from ._dummy import *
def macos_supported_version():
sysver = platform.mac_ver()[0] #typically 10.14.2 or 12.3
major = int(sysver.split('.')[0])
if major < 10:
return False
elif major >= 11:
return True
else:
minor = int(sysver.split('.')[1])
if minor < 14:
return False
else:
return True

if sys.platform == "darwin":
if macos_supported_version():
from ._mac_detect import *
del V
elif sys.platform == "win32" and int(platform.release()) >= 10:
else:
from ._dummy import *
elif sys.platform == "win32" and platform.release().isdigit() and int(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(platform.version().split('.')[2])
Expand All @@ -29,4 +41,4 @@
else:
from ._dummy import *

del sys, platform
del sys, platform
9 changes: 9 additions & 0 deletions syncplay/vendor/darkdetect/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#-----------------------------------------------------------------------------
# Copyright (C) 2019 Alberto Sottile
#
# Distributed under the terms of the 3-clause BSD License.
#-----------------------------------------------------------------------------

import darkdetect

print('Current theme: {}'.format(darkdetect.theme()))
5 changes: 5 additions & 0 deletions syncplay/vendor/darkdetect/_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Distributed under the terms of the 3-clause BSD License.
#-----------------------------------------------------------------------------

import typing

def theme():
return None

Expand All @@ -12,3 +14,6 @@ def isDark():

def isLight():
return None

def listener(callback: typing.Callable[[str], None]) -> None:
raise NotImplementedError()
13 changes: 11 additions & 2 deletions syncplay/vendor/darkdetect/_linux_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import subprocess


def theme():
# Here we just triage to GTK settings for now
try:
Expand All @@ -18,7 +17,7 @@ def theme():
return 'Light'
# we have a string, now remove start and end quote
theme = stdout.lower().strip()[1:-1]
if theme.endswith('-dark'):
if '-dark' in theme.lower():
return 'Dark'
else:
return 'Light'
Expand All @@ -28,3 +27,13 @@ def isDark():

def isLight():
return theme() == 'Light'

# def listener(callback: typing.Callable[[str], None]) -> None:
def listener(callback):
with subprocess.Popen(
('gsettings', 'monitor', 'org.gnome.desktop.interface', 'gtk-theme'),
stdout=subprocess.PIPE,
universal_newlines=True,
) as p:
for line in p.stdout:
callback('Dark' if '-dark' in line.strip().removeprefix("gtk-theme: '").removesuffix("'").lower() else 'Light')
4 changes: 4 additions & 0 deletions syncplay/vendor/darkdetect/_mac_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ def isDark():

def isLight():
return theme() == 'Light'

#def listener(callback: typing.Callable[[str], None]) -> None:
def listener(callback):
raise NotImplementedError()
100 changes: 99 additions & 1 deletion syncplay/vendor/darkdetect/_windows_detect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
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.
Expand All @@ -21,4 +76,47 @@ def isDark():

def isLight():
if theme() is not None:
return theme() == 'Light'
return theme() == 'Light'

#def listener(callback: typing.Callable[[str], None]) -> None:
def listener(callback):
hKey = ctypes.wintypes.HKEY()
advapi32.RegOpenKeyExA(
ctypes.wintypes.HKEY(0x80000001), # HKEY_CURRENT_USER
ctypes.wintypes.LPCSTR(b'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize'),
ctypes.wintypes.DWORD(),
ctypes.wintypes.DWORD(0x00020019), # KEY_READ
ctypes.byref(hKey),
)

dwSize = ctypes.wintypes.DWORD(ctypes.sizeof(ctypes.wintypes.DWORD))
queryValueLast = ctypes.wintypes.DWORD()
queryValue = ctypes.wintypes.DWORD()
advapi32.RegQueryValueExA(
hKey,
ctypes.wintypes.LPCSTR(b'AppsUseLightTheme'),
ctypes.wintypes.LPDWORD(),
ctypes.wintypes.LPDWORD(),
ctypes.cast(ctypes.byref(queryValueLast), ctypes.wintypes.LPBYTE),
ctypes.byref(dwSize),
)

while True:
advapi32.RegNotifyChangeKeyValue(
hKey,
ctypes.wintypes.BOOL(True),
ctypes.wintypes.DWORD(0x00000004), # REG_NOTIFY_CHANGE_LAST_SET
ctypes.wintypes.HANDLE(None),
ctypes.wintypes.BOOL(False),
)
advapi32.RegQueryValueExA(
hKey,
ctypes.wintypes.LPCSTR(b'AppsUseLightTheme'),
ctypes.wintypes.LPDWORD(),
ctypes.wintypes.LPDWORD(),
ctypes.cast(ctypes.byref(queryValue), ctypes.wintypes.LPBYTE),
ctypes.byref(dwSize),
)
if queryValueLast.value != queryValue.value:
queryValueLast.value = queryValue.value
callback('Light' if queryValue.value else 'Dark')

0 comments on commit 034c7cc

Please sign in to comment.