-
Notifications
You must be signed in to change notification settings - Fork 164
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
Fix Dbus wrapper, and use glib/gio GDbus via introspection, remove the dbus-python dependency #277
Comments
It's a shame to drop this interface, but it's becoming problematic to use with Flatpak. We should revisit these in the future, and plug them in org.gnome.GTG. ref #277
Mart suggested that we should eliminate the dbus-python dependency by using glib/gio GDBus stuff via introspection to achieve the same thing. I guess this should be done as part of this ticket, so renaming the title (in case anyone out there is looking at this ticket and wants to tackle it). |
It's a shame to drop this interface, but it's becoming problematic to use with Flatpak. We should revisit these in the future, and plug them in org.gnome.GTG. ref getting-things-gnome#277
I managed to port the timer to gio dbus (which is the only place we use dbus ATM). Unfortunately I can't get it to attach a callback to the proper signal. It seems to be a problem with the system bus, I can attach callbacks to signals in the session bus just fine but when it comes to the system bus it just... doesn't do it. There are no errors or anything. Haven't had any luck asking in #gtk, #python and Gnome Discourse. Leaving this code here in case someone knows the proper incantation: system_bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
system_bus.signal_subscribe('org.freedesktop.login1',
'org.freedesktop.login1.Manager',
'PrepareForSleep',
'/org/freedesktop/login1',
None,
Gio.DBusSignalFlags.NONE,
on_prepare_for_sleep,
None) The callback: def on_prepare_for_sleep(connection, sender_name, object_path,
interface_name, signal_name, parameters,
*user_data):
"""Handle dbus prepare for sleep signal."""
print('Called') |
@diegogangl from gi.repository import GLib
GLib.MainLoop().run() However, as you can see, this will stop application flow, in other words GTG won't continue executing. I tried subscribing in the |
You are right, this might be the thing. Maybe you need to connect this way to subscribe self.connection = Gio.DBusConnection.new_for_address_sync(
self.__bus_address,
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT |
Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION,
None, None) |
I looked into D-Feet a bit, and it seems it doesn't do anything special.
I tried subscribing inside GTGs I also tried your code (which is actually from D-Feet), with the bus address being the system bus address Gio returns, but no success either: system_address = Gio.dbus_address_get_for_bus_sync(Gio.BusType.SYSTEM, None)
system_bus = Gio.DBusConnection.new_for_address_sync(system_address,
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT | Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION,
None,
None) And yes, I made sure that the method gets called. |
Wait, I was wrong. That's not how the connection gets done. I took it from: Looking at the if block they actually connect in the same way as the first snippet I posted |
I tried to check if D-Feets signal works and trace it down "until it works". I used the following git diff: diff --git a/src/dfeet/bus_watch.py b/src/dfeet/bus_watch.py
index a6472ed..fd552cd 100644
--- a/src/dfeet/bus_watch.py
+++ b/src/dfeet/bus_watch.py
@@ -115,6 +115,24 @@ class BusNameBox(Gtk.VBox):
class BusWatch(object):
"""watch for a given bus"""
def __init__(self, data_dir, bus_address):
+ # print("Registering for", bus_address)
+ if bus_address == Gio.BusType.SYSTEM:
+ # print("Registering")
+ # Gio.bus_get_sync(Gio.BusType.SYSTEM, None).start_message_processing()
+ # Gio.bus_get_sync(Gio.BusType.SYSTEM, None).flush_sync(None)
+ def test(*args):
+ print("I AM HERE", args)
+ Gio.bus_get_sync(Gio.BusType.SYSTEM, None).signal_subscribe(None, None, None, None, None, 0, test, None)
+ # Gio.bus_get_sync(Gio.BusType.SYSTEM, None).flush_sync(None)
+ def test(*args):
+ print("SECOND", args)
+ Gio.bus_get_sync(Gio.BusType.SYSTEM, None).signal_subscribe(None, None, None, None, None, 0, test, None)
+ def test(*args):
+ print("THIRD", args)
+ Gio.bus_get_sync(Gio.BusType.SYSTEM, None).signal_subscribe(None, None, None, None, None, 0, test, None)
+ def test(*args):
+ print("FOURTH", args)
+ Gio.bus_get_sync(Gio.BusType.SYSTEM, None).signal_subscribe(None, None, None, None, None, 0, test, None)
self.__data_dir = data_dir
self.__bus_address = bus_address
# setup UI
@@ -146,6 +164,12 @@ class BusWatch(object):
self.connection.signal_subscribe(None, "org.freedesktop.DBus", "NameOwnerChanged",
None, None, 0, self.__name_owner_changed_cb, None)
+ # def test(*args):
+ # print(self.__bus_address, args)
+
+ # self.connection.signal_subscribe(None, None, None,
+ # None, None, 0, test, None)
+
# refilter if someone wants to filter the busbox list
self.__bus_name_filter.connect("changed",
self.__bus_name_filter_changed_cb)
diff --git a/src/dfeet/window.py b/src/dfeet/window.py
index 01b6032..dfa0306 100644
--- a/src/dfeet/window.py
+++ b/src/dfeet/window.py
@@ -126,8 +126,12 @@ class DFeetWindow(Gtk.ApplicationWindow):
def __action_connect_system_bus_cb(self, action, parameter):
"""connect to system bus"""
try:
+ # print("connecting to systembus cb")
if self.system_bus is not None:
return
+ # def test(*args):
+ # print("BEFORE BUS WATCH", args)
+ # Gio.bus_get_sync(Gio.BusType.SYSTEM, None).signal_subscribe(None, None, None, None, None, 0, test, None)
bw = BusWatch(self.data_dir, Gio.BusType.SYSTEM)
self.system_bus = bw.box_bus
self.stack.add_titled(self.system_bus, 'System Bus', 'System Bus') For some reason, it "randomly" works. I also noticed if I don't start_message_processing + flush (and even then it would just "sometimes" work), the first "working" signal would get an NameAcquired signal, but only once:
Then that and further ones would print other incoming signals. |
They are calling it at some point late in their main window, while we are creating the timer in the application constructor. I remember moving it to the end of |
Actually, I found it out. See the PR #479, or: D-Feet keeps a reference to the system dbus, which keeps the connection alive. In our case, we don't and thus when it goes out of scope, the connection gets destroyed and the signals get disconnected. |
Is there any plan to implement this in next release ? @Neui |
GTG used to expose some of its functionality to dbus using some custom code in the dbus wrapper class (
dbus.py
). Nowadays, GtkApplication registers itself with the same name as the app id which conflicts with the old way, since both end up with the same bus name.My " solution " was to change the well known name in the dbus wrapper. So now GTG has two dbus interfaces. It would be a shame to throw away the old one since it was nicer and more specific to gtg. A real solution would be to add those functions to the well know name exposed by GtkApplication.
It would be great if someone with dbus knowledge could help out here!
The text was updated successfully, but these errors were encountered: