mirror of
https://github.com/libratbag/piper.git
synced 2026-02-20 15:43:51 -05:00
Sync ratbagd from libratbag
This commit is contained in:
@@ -62,6 +62,18 @@ class RatbagErrorCode(IntEnum):
|
||||
IMPLEMENTATION = -1004
|
||||
|
||||
|
||||
class RatbagdIncompatible(Exception):
|
||||
"""ratbagd is incompatible with this client"""
|
||||
def __init__(self, ratbagd_version, required_version):
|
||||
super().__init__()
|
||||
self.ratbagd_version = ratbagd_version
|
||||
self.required_version = required_version
|
||||
self.message = "ratbagd API version is {} but we require {}".format(ratbagd_version, required_version)
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
|
||||
class RatbagdUnavailable(Exception):
|
||||
"""Signals DBus is unavailable or the ratbagd daemon is not available."""
|
||||
pass
|
||||
@@ -196,7 +208,7 @@ class _RatbagdDBus(GObject.GObject):
|
||||
# Calls a method synchronously on the bus, using the given method name,
|
||||
# type signature and values.
|
||||
#
|
||||
# It the result is valid, it is returned. Invalid results raise the
|
||||
# If the result is valid, it is returned. Invalid results raise the
|
||||
# appropriate RatbagError* or RatbagdDBus* exception, or GLib.Error if
|
||||
# it is an unexpected exception that probably shouldn't be passed up to
|
||||
# the UI.
|
||||
@@ -238,11 +250,13 @@ class Ratbagd(_RatbagdDBus):
|
||||
(GObject.SignalFlags.RUN_FIRST, None, ()),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, api_version):
|
||||
super().__init__("Manager", None)
|
||||
result = self._get_dbus_property("Devices") or []
|
||||
self._devices = [RatbagdDevice(objpath) for objpath in result]
|
||||
self._proxy.connect("notify::g-name-owner", self._on_name_owner_changed)
|
||||
if self.api_version != api_version:
|
||||
raise RatbagdIncompatible(self.api_version or -1, api_version)
|
||||
|
||||
def _on_name_owner_changed(self, *kwargs):
|
||||
self.emit("daemon-disappeared")
|
||||
@@ -261,6 +275,10 @@ class Ratbagd(_RatbagdDBus):
|
||||
self.emit("device-removed", device)
|
||||
self.notify("devices")
|
||||
|
||||
@GObject.Property
|
||||
def api_version(self):
|
||||
return self._get_dbus_property("APIVersion")
|
||||
|
||||
@GObject.Property
|
||||
def devices(self):
|
||||
"""A list of RatbagdDevice objects supported by ratbagd."""
|
||||
|
||||
Reference in New Issue
Block a user