diff options
Diffstat (limited to 'libdino')
-rw-r--r-- | libdino/src/dbus/login1.vala | 7 | ||||
-rw-r--r-- | libdino/src/dbus/notifications.vala | 15 | ||||
-rw-r--r-- | libdino/src/service/connection_manager.vala | 12 | ||||
-rw-r--r-- | libdino/src/service/notification_events.vala | 69 |
4 files changed, 62 insertions, 41 deletions
diff --git a/libdino/src/dbus/login1.vala b/libdino/src/dbus/login1.vala index 904f389c..da358a99 100644 --- a/libdino/src/dbus/login1.vala +++ b/libdino/src/dbus/login1.vala @@ -5,14 +5,13 @@ public interface Login1Manager : Object { public signal void PrepareForSleep(bool suspend); } -public static Login1Manager? get_login1() { - Login1Manager? login1 = null; +public static async Login1Manager? get_login1() { try { - login1 = Bus.get_proxy_sync(BusType.SYSTEM, "org.freedesktop.login1", "/org/freedesktop/login1"); + return yield Bus.get_proxy(BusType.SYSTEM, "org.freedesktop.login1", "/org/freedesktop/login1"); } catch (IOError e) { stderr.printf("%s\n", e.message); } - return login1; + return null; } }
\ No newline at end of file diff --git a/libdino/src/dbus/notifications.vala b/libdino/src/dbus/notifications.vala index 68401440..25a567df 100644 --- a/libdino/src/dbus/notifications.vala +++ b/libdino/src/dbus/notifications.vala @@ -7,23 +7,22 @@ namespace Dino { public signal void notification_closed (uint32 id, uint32 reason); - public abstract uint32 notify(string app_name, uint32 replaces_id, string app_icon, string summary, + public abstract async uint32 notify(string app_name, uint32 replaces_id, string app_icon, string summary, string body, string[] actions, HashTable<string, Variant> hints, int32 expire_timeout) throws DBusError, IOError; - public abstract void get_capabilities(out string[] capabilities) throws Error; + public abstract async void get_capabilities(out string[] capabilities) throws Error; - public abstract void close_notification(uint id) throws DBusError, IOError; + public abstract async void close_notification(uint id) throws DBusError, IOError; - public abstract void get_server_information(out string name, out string vendor, out string version, out string spec_version) throws DBusError, IOError; + public abstract async void get_server_information(out string name, out string vendor, out string version, out string spec_version) throws DBusError, IOError; } - public static DBusNotifications? get_notifications_dbus() { - DBusNotifications? upower = null; + public static async DBusNotifications? get_notifications_dbus() { try { - upower = Bus.get_proxy_sync(BusType.SESSION, "org.freedesktop.Notifications", "/org/freedesktop/Notifications"); + 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 upower; + return null; } }
\ No newline at end of file diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala index d114b9ae..43580c06 100644 --- a/libdino/src/service/connection_manager.vala +++ b/libdino/src/service/connection_manager.vala @@ -104,10 +104,14 @@ public class ConnectionManager : Object { network_monitor.network_changed.connect(on_network_changed); network_monitor.notify["connectivity"].connect(on_network_changed); } - login1 = get_login1(); - if (login1 != null) { - login1.PrepareForSleep.connect(on_prepare_for_sleep); - } + + get_login1.begin((_, res) => { + login1 = get_login1.end(res); + if (login1 != null) { + login1.PrepareForSleep.connect(on_prepare_for_sleep); + } + }); + Timeout.add_seconds(60, () => { foreach (Account account in connections.keys) { if (connections[account].last_activity != null && diff --git a/libdino/src/service/notification_events.vala b/libdino/src/service/notification_events.vala index 6f1d0fd4..2408aadc 100644 --- a/libdino/src/service/notification_events.vala +++ b/libdino/src/service/notification_events.vala @@ -12,7 +12,9 @@ public class NotificationEvents : StreamInteractionModule, Object { public signal void notify_content_item(ContentItem content_item, Conversation conversation); private StreamInteractor stream_interactor; - private NotificationProvider? notifier; + private Future<NotificationProvider> notifier; + private Promise<NotificationProvider> notifier_promise; + private bool notifier_outstanding = true; public static void start(StreamInteractor stream_interactor) { NotificationEvents m = new NotificationEvents(stream_interactor); @@ -22,24 +24,28 @@ public class NotificationEvents : StreamInteractionModule, Object { public NotificationEvents(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - stream_interactor.get_module(ContentItemStore.IDENTITY).new_item.connect(on_content_item_received); - stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect(on_received_subscription_request); + stream_interactor.get_module(ContentItemStore.IDENTITY).new_item.connect((item, conversation) => on_content_item_received.begin(item, conversation)); + stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect((jid, account) => on_received_subscription_request.begin(jid, account)); - stream_interactor.get_module(MucManager.IDENTITY).invite_received.connect(on_invite_received); - stream_interactor.get_module(MucManager.IDENTITY).voice_request_received.connect(on_voice_request_received); + stream_interactor.get_module(MucManager.IDENTITY).invite_received.connect((account, room_jid, from_jid, password, reason) => on_invite_received.begin(account, room_jid, from_jid, password, reason)); + stream_interactor.get_module(MucManager.IDENTITY).voice_request_received.connect((account, room_jid, from_jid, nick) => on_voice_request_received.begin(account, room_jid, from_jid, nick)); - stream_interactor.get_module(Calls.IDENTITY).call_incoming.connect(on_call_incoming); - stream_interactor.connection_manager.connection_error.connect((account, error) => notifier.notify_connection_error.begin(account, error)); - stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect(on_focused_in); + stream_interactor.get_module(Calls.IDENTITY).call_incoming.connect((call, state, conversation, video) => on_call_incoming.begin(call, state, conversation, video)); + stream_interactor.connection_manager.connection_error.connect((account, error) => on_connection_error(account, error)); + stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect((conversation) => on_focused_in.begin(conversation)); + + notifier_promise = new Promise<NotificationProvider>(); + notifier = notifier_promise.future; } - public void register_notification_provider(NotificationProvider notification_provider) { - if (notifier == null || notifier.get_priority() < notification_provider.get_priority()) { - notifier = notification_provider; + public async void register_notification_provider(NotificationProvider notification_provider) { + if (notifier_outstanding || (yield notifier.wait_async()).get_priority() < notification_provider.get_priority()) { + notifier_outstanding = false; + notifier_promise.set_value(notification_provider); } } - private void on_content_item_received(ContentItem item, Conversation conversation) { + private async void on_content_item_received(ContentItem item, Conversation conversation) { ContentItem last_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_latest(conversation); if (item.id != last_item.id) return; @@ -71,7 +77,8 @@ public class NotificationEvents : StreamInteractionModule, Object { notify_content_item(item, conversation); if (notify != Conversation.NotifySetting.OFF) { - notifier.notify_message.begin(message, conversation, conversation_display_name, participant_display_name); + NotificationProvider notifier = yield notifier.wait_async(); + yield notifier.notify_message(message, conversation, conversation_display_name, participant_display_name); } break; case FileItem.TYPE: @@ -84,7 +91,8 @@ public class NotificationEvents : StreamInteractionModule, Object { notify_content_item(item, conversation); if (notify != Conversation.NotifySetting.OFF) { - notifier.notify_file.begin(file_transfer, conversation, is_image, conversation_display_name, participant_display_name); + NotificationProvider notifier = yield notifier.wait_async(); + yield notifier.notify_file(file_transfer, conversation, is_image, conversation_display_name, participant_display_name); } break; case CallItem.TYPE: @@ -93,23 +101,27 @@ public class NotificationEvents : StreamInteractionModule, Object { } } - private void on_voice_request_received(Account account, Jid room_jid, Jid from_jid, string nick) { + private async void on_voice_request_received(Account account, Jid room_jid, Jid from_jid, string nick) { Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(room_jid, account, Conversation.Type.GROUPCHAT); if (conversation == null) return; - notifier.notify_voice_request.begin(conversation, from_jid); + + NotificationProvider notifier = yield notifier.wait_async(); + yield notifier.notify_voice_request(conversation, from_jid); } - private void on_received_subscription_request(Jid jid, Account account) { + private async void on_received_subscription_request(Jid jid, Account account) { Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); if (stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus(conversation)) return; - notifier.notify_subscription_request.begin(conversation); + NotificationProvider notifier = yield notifier.wait_async(); + yield notifier.notify_subscription_request(conversation); } - private void on_call_incoming(Call call, CallState call_state, Conversation conversation, bool video) { + private async void on_call_incoming(Call call, CallState call_state, Conversation conversation, bool video) { string conversation_display_name = get_conversation_display_name(stream_interactor, conversation, null); - notifier.notify_call.begin(call, conversation, video, conversation_display_name); + NotificationProvider notifier = yield notifier.wait_async(); + yield notifier.notify_call(call, conversation, video, conversation_display_name); call.notify["state"].connect(() => { if (call.state != Call.State.RINGING) { notifier.retract_call_notification.begin(call, conversation); @@ -117,7 +129,7 @@ public class NotificationEvents : StreamInteractionModule, Object { }); } - private void on_invite_received(Account account, Jid room_jid, Jid from_jid, string? password, string? reason) { + private async void on_invite_received(Account account, Jid room_jid, Jid from_jid, string? password, string? reason) { string inviter_display_name; if (room_jid.equals_bare(from_jid)) { Conversation conversation = new Conversation(room_jid, account, Conversation.Type.GROUPCHAT); @@ -126,12 +138,19 @@ public class NotificationEvents : StreamInteractionModule, Object { Conversation direct_conversation = new Conversation(from_jid, account, Conversation.Type.CHAT); inviter_display_name = get_participant_display_name(stream_interactor, direct_conversation, from_jid); } - notifier.notify_muc_invite.begin(account, room_jid, from_jid, inviter_display_name); + NotificationProvider notifier = yield notifier.wait_async(); + yield notifier.notify_muc_invite(account, room_jid, from_jid, inviter_display_name); + } + + private async void on_connection_error(Account account, ConnectionManager.ConnectionError error) { + NotificationProvider notifier = yield notifier.wait_async(); + yield notifier.notify_connection_error(account, error); } - private void on_focused_in(Conversation conversation) { - notifier.retract_content_item_notifications.begin(); - notifier.retract_conversation_notifications.begin(conversation); + private async void on_focused_in(Conversation conversation) { + NotificationProvider notifier = yield notifier.wait_async(); + yield notifier.retract_content_item_notifications(); + yield notifier.retract_conversation_notifications(conversation); } } |