feat(main): implement def _read_portal_dark_preference
This commit is contained in:
parent
051413472b
commit
822e8d8989
1 changed files with 49 additions and 0 deletions
|
|
@ -43,3 +43,52 @@ def _unwrap_qvariant(value):
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
return unwrapped
|
return unwrapped
|
||||||
|
|
||||||
|
|
||||||
|
# _read_portal_dark_preference: function definition for ScanSlicer behavior.
|
||||||
|
def _read_portal_dark_preference():
|
||||||
|
try:
|
||||||
|
from PySide6.QtDBus import QDBusConnection, QDBusInterface, QDBusMessage
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
bus = QDBusConnection.sessionBus()
|
||||||
|
if not bus.isConnected():
|
||||||
|
return None
|
||||||
|
|
||||||
|
iface = QDBusInterface(
|
||||||
|
"org.freedesktop.portal.Desktop",
|
||||||
|
"/org/freedesktop/portal/desktop",
|
||||||
|
"org.freedesktop.portal.Settings",
|
||||||
|
bus,
|
||||||
|
)
|
||||||
|
if not iface.isValid():
|
||||||
|
return None
|
||||||
|
|
||||||
|
for method in ("ReadOne", "Read"):
|
||||||
|
reply = iface.call(method, "org.freedesktop.appearance", "color-scheme")
|
||||||
|
if reply.type() == QDBusMessage.MessageType.ErrorMessage:
|
||||||
|
continue
|
||||||
|
|
||||||
|
args = reply.arguments()
|
||||||
|
if not args:
|
||||||
|
continue
|
||||||
|
|
||||||
|
raw_value = _unwrap_qvariant(args[0])
|
||||||
|
if isinstance(raw_value, dict) and "color-scheme" in raw_value:
|
||||||
|
raw_value = _unwrap_qvariant(raw_value["color-scheme"])
|
||||||
|
if isinstance(raw_value, (list, tuple)) and raw_value:
|
||||||
|
raw_value = _unwrap_qvariant(raw_value[0])
|
||||||
|
|
||||||
|
try:
|
||||||
|
color_scheme = int(raw_value)
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# XDG portal color-scheme values:
|
||||||
|
# 0 = no preference, 1 = prefer dark, 2 = prefer light
|
||||||
|
if color_scheme == 1:
|
||||||
|
return True
|
||||||
|
if color_scheme == 2:
|
||||||
|
return False
|
||||||
|
return None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue