diff options
| author | fiaxh <git@lightrise.org> | 2025-04-19 14:34:44 +0200 |
|---|---|---|
| committer | fiaxh <git@lightrise.org> | 2025-12-19 12:14:28 +0100 |
| commit | f777856517ce39c4004be61c2661cc15377648fc (patch) | |
| tree | 2fad5d39e0c076cf42642554cd09b39ddb936791 /libdino/src | |
| parent | b4697cd2637453a7ece57d8e38edd05d36d9ffae (diff) | |
Use GNotifications if Bus.get_proxy never returns the dbus notifications interface
Diffstat (limited to 'libdino/src')
| -rw-r--r-- | libdino/src/dbus/notifications.vala | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/libdino/src/dbus/notifications.vala b/libdino/src/dbus/notifications.vala index 25a567df..2a9deb64 100644 --- a/libdino/src/dbus/notifications.vala +++ b/libdino/src/dbus/notifications.vala @@ -17,12 +17,34 @@ namespace Dino { public abstract async void get_server_information(out string name, out string vendor, out string version, out string spec_version) throws DBusError, IOError; } + // This function will always return. Sometimes Glib.Bus.get_proxy doesn't return, but this function covers that with a timeout. + // Returns null if the dbus notifications interface can't be obtained (if timeout or exception) public static async DBusNotifications? get_notifications_dbus() { - try { - return yield Bus.get_proxy(BusType.SESSION, "org.freedesktop.Notifications", "/org/freedesktop/Notifications"); - } catch (IOError e) { - warning("Couldn't get org.freedesktop.Notifications DBus instance: %s\n", e.message); - } - return null; + DBusNotifications? ret = null; + Cancellable cancellable = new Cancellable(); + + uint timeout_handle_id = Timeout.add_seconds(10, () => { + warning("Timeout waiting for org.freedesktop.Notifications DBus instance"); + cancellable.cancel(); + Idle.add(get_notifications_dbus.callback); + return false; + }); + + Bus.get_proxy.begin<DBusNotifications>(BusType.SESSION, "org.freedesktop.Notifications", "/org/freedesktop/Notifications", 0, cancellable, (_, res) => { + try { + ret = Bus.get_proxy.end(res); + } catch(IOError e) { + warning("Couldn't get org.freedesktop.Notifications DBus instance: %s", e.message); + } + if (timeout_handle_id != 0) { + Source.remove(timeout_handle_id); + Idle.add(get_notifications_dbus.callback); + } + }); + + yield; + timeout_handle_id = 0; + + return ret; } }
\ No newline at end of file |
