aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2022-02-01 17:38:15 +0100
committerfiaxh <git@lightrise.org>2022-02-01 23:37:54 +0100
commitb7ca33a37de5dd2ecffa7575681c6009996b7ba2 (patch)
tree838f4e36a8052cd5d287069df7b76b7fbd6fb7bd /main
parent1e63cb3bd935ad42af7b203efc5f4f83ae131e58 (diff)
downloaddino-b7ca33a37de5dd2ecffa7575681c6009996b7ba2.tar.gz
dino-b7ca33a37de5dd2ecffa7575681c6009996b7ba2.zip
Initialize and use dbus interfaces async
related #1155
Diffstat (limited to 'main')
-rw-r--r--main/src/ui/application.vala20
-rw-r--r--main/src/ui/notifier_freedesktop.vala43
2 files changed, 29 insertions, 34 deletions
diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala
index 4f97b7b3..62f01bcb 100644
--- a/main/src/ui/application.vala
+++ b/main/src/ui/application.vala
@@ -47,11 +47,21 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
}
NotificationEvents notification_events = stream_interactor.get_module(NotificationEvents.IDENTITY);
- notification_events.register_notification_provider(new GNotificationsNotifier(stream_interactor));
- FreeDesktopNotifier? free_desktop_notifier = FreeDesktopNotifier.try_create(stream_interactor);
- if (free_desktop_notifier != null) {
- notification_events.register_notification_provider(free_desktop_notifier);
- }
+ get_notifications_dbus.begin((_, res) => {
+ // It might take a bit to get the interface. NotificationEvents will queue any notifications in the meantime.
+ try {
+ DBusNotifications? dbus_notifications = get_notifications_dbus.end(res);
+ if (dbus_notifications != null) {
+ FreeDesktopNotifier free_desktop_notifier = new FreeDesktopNotifier(stream_interactor, dbus_notifications);
+ notification_events.register_notification_provider.begin(free_desktop_notifier);
+ } else {
+ notification_events.register_notification_provider.begin(new GNotificationsNotifier(stream_interactor));
+ }
+ } catch (Error e) {
+ debug("Failed accessing fdo notification server: %s", e.message);
+ }
+ });
+
notification_events.notify_content_item.connect((content_item, conversation) => {
// Set urgency hint also if (normal) notifications are disabled
// Don't set urgency hint in GNOME, produces "Window is active" notification
diff --git a/main/src/ui/notifier_freedesktop.vala b/main/src/ui/notifier_freedesktop.vala
index e8e2ba1d..dfc5b28b 100644
--- a/main/src/ui/notifier_freedesktop.vala
+++ b/main/src/ui/notifier_freedesktop.vala
@@ -17,16 +17,16 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
private HashMap<uint32, HashMap<string, ListenerFuncWrapper>> action_listeners = new HashMap<uint32, HashMap<string, ListenerFuncWrapper>>();
private HashMap<Call, uint32> call_notifications = new HashMap<Call, uint32>(Call.hash_func, Call.equals_func);
- private FreeDesktopNotifier(StreamInteractor stream_interactor) {
+ public FreeDesktopNotifier(StreamInteractor stream_interactor, DBusNotifications dbus_notifications) {
this.stream_interactor = stream_interactor;
+ this.dbus_notifications = dbus_notifications;
+ init_dbus_notifications.begin();
}
- private void set_dbus_notifications(DBusNotifications dbus_notifications) throws Error {
- this.dbus_notifications = dbus_notifications;
-
+ private async void init_dbus_notifications() throws Error {
string[] caps;
- dbus_notifications.get_capabilities(out caps);
+ yield dbus_notifications.get_capabilities(out caps);
foreach (string cap in caps) {
switch (cap) {
case "body-markup":
@@ -49,21 +49,6 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
});
}
- public static FreeDesktopNotifier? try_create(StreamInteractor stream_interactor) {
- DBusNotifications? dbus_notifications = get_notifications_dbus();
- if (dbus_notifications == null) return null;
-
- try {
- FreeDesktopNotifier notifier = new FreeDesktopNotifier(stream_interactor);
- notifier.set_dbus_notifications(dbus_notifications);
- return notifier;
- } catch (Error e) {
- debug("Failed accessing fdo notification server: %s", e.message);
- }
-
- return null;
- }
-
public double get_priority() {
return 1;
}
@@ -111,7 +96,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
hash_table["desktop-entry"] = new Variant.string(Dino.Application.get_default().get_application_id());
string[] actions = new string[] {"default", "Open conversation"};
try {
- uint32 notification_id = dbus_notifications.notify("Dino", replace_id, "", conversation_display_name, body, actions, hash_table, -1);
+ uint32 notification_id = yield dbus_notifications.notify("Dino", replace_id, "", conversation_display_name, body, actions, hash_table, -1);
content_notifications[conversation] = notification_id;
add_action_listener(notification_id, "default", () => {
@@ -134,7 +119,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
hash_table["desktop-entry"] = new Variant.string(Dino.Application.get_default().get_application_id());
string[] actions = new string[] {"default", "Open conversation", "reject", _("Reject"), "accept", _("Accept")};
try {
- uint32 notification_id = dbus_notifications.notify("Dino", 0, "", summary, body, actions, hash_table, 0);
+ uint32 notification_id = yield dbus_notifications.notify("Dino", 0, "", summary, body, actions, hash_table, 0);
call_notifications[call] = notification_id;
add_action_listener(notification_id, "default", () => {
@@ -157,7 +142,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
if (!call_notifications.has_key(call)) return;
uint32 notification_id = call_notifications[call];
try {
- dbus_notifications.close_notification(notification_id);
+ yield dbus_notifications.close_notification(notification_id);
action_listeners.unset(notification_id);
call_notifications.unset(call);
} catch (Error e) { }
@@ -172,7 +157,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
hash_table["desktop-entry"] = new Variant.string(Dino.Application.get_default().get_application_id());
string[] actions = new string[] {"default", "Open conversation", "accept", _("Accept"), "deny", _("Deny")};
try {
- uint32 notification_id = dbus_notifications.notify("Dino", 0, "", summary, body, actions, hash_table, -1);
+ uint32 notification_id = yield dbus_notifications.notify("Dino", 0, "", summary, body, actions, hash_table, -1);
if (!conversation_notifications.has_key(conversation)) {
conversation_notifications[conversation] = new ArrayList<uint32>();
@@ -210,7 +195,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
HashTable<string, Variant> hash_table = new HashTable<string, Variant>(null, null);
hash_table["desktop-entry"] = new Variant.string(Dino.Application.get_default().get_application_id());
try {
- dbus_notifications.notify("Dino", 0, "im.dino.Dino", summary, body, new string[]{}, hash_table, -1);
+ yield dbus_notifications.notify("Dino", 0, "im.dino.Dino", summary, body, new string[]{}, hash_table, -1);
} catch (Error e) {
warning("Failed showing connection error notification: %s", e.message);
}
@@ -232,7 +217,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
string[] actions = new string[] {"default", "", "reject", _("Reject"), "accept", _("Accept")};
try {
- uint32 notification_id = dbus_notifications.notify("Dino", 0, "", summary, body, actions, hash_table, -1);
+ uint32 notification_id = yield dbus_notifications.notify("Dino", 0, "", summary, body, actions, hash_table, -1);
Conversation group_conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(room_jid, account, Conversation.Type.GROUPCHAT);
add_action_listener(notification_id, "default", () => {
@@ -265,7 +250,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
string[] actions = new string[] {"deny", _("Deny"), "accept", _("Accept")};
try {
- uint32 notification_id = dbus_notifications.notify("Dino", 0, "", summary, body, actions, hash_table, -1);
+ uint32 notification_id = yield dbus_notifications.notify("Dino", 0, "", summary, body, actions, hash_table, -1);
add_action_listener(notification_id, "accept", () => {
GLib.Application.get_default().activate_action("accept-voice-request", new Variant.int32(conversation.id));
@@ -282,7 +267,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
if (content_notifications != null) {
foreach (uint32 id in content_notifications.values) {
try {
- dbus_notifications.close_notification(id);
+ yield dbus_notifications.close_notification(id);
} catch (Error e) { }
}
content_notifications.clear();
@@ -292,7 +277,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
public async void retract_conversation_notifications(Conversation conversation) {
if (content_notifications.has_key(conversation)) {
try {
- dbus_notifications.close_notification(content_notifications[conversation]);
+ yield dbus_notifications.close_notification(content_notifications[conversation]);
} catch (Error e) { }
}
content_notifications.unset(conversation);