I'm trying to make my GTK app responsive to network connection state changes. My approach is what I said in the question: Listen on a (NetworkManager) DBus signal.
I have a python3 GTK app (a very minimal one, I should add), using python-gi. As python-dbus (aka "import dbus") is deprecated to the best of my knowledge, I'd like to use Gio via python-gi.
I have an older script that listens for the signal I'm interested in on the system DBus which uses "import dbus" with this code:
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(NMSignalHandler,
dbus_interface=NM_INTERFACE,
signal_name='StateChanged')
(followed by a gobject.MainLoop().run())
I thought this would be relatively straightforward to "port" to Gio, but even after two hours of reading the docs, I don't see how to do that. Any help would be appreciated.
I already tried using Gio.NetworkMonitor.get_default() and its 'network-changed' signal, but it appears to report with net_available (second parameter) always being true and the default monitor doesn't seem to report a sensible result either.
I would deeply appreciate any help.