Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use xdg-desktop-portal on Linux #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions darkdetect/_linux_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@
import subprocess

def theme():
try:
# Using the freedesktop portals for checking dark mode
import jeepney.io.blocking
import jeepney

portal = jeepney.DBusAddress(
object_path='/org/freedesktop/portal/desktop',
bus_name='org.freedesktop.portal.Desktop',
interface='org.freedesktop.portal.Settings'
)

con = jeepney.io.blocking.open_dbus_connection(bus='SESSION')
method = jeepney.new_method_call(portal, 'Read', 'ss', ('org.freedesktop.appearance', 'color-scheme'))
darkmode = con.send_and_get_reply(method).body[0][1][1]

if darkmode == 1:
return 'Dark'
else:
return 'Light'
except Exception:
pass

try:
#Using the freedesktop specifications for checking dark mode
out = subprocess.run(
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ build-backend = "setuptools.build_meta"
name = "darkdetect"
description = "Detect OS Dark Mode from Python"
readme = "README.md"
requires-python = ">=3.6"
requires-python = ">=3.7"
dynamic = [ "version" ]
classifiers = [
"License :: OSI Approved :: BSD License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows :: Windows 10",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
]
dependencies = [
"jeepney; platform_system=='Linux'"
]

[project.license]
Expand Down