diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala index cf75af46..50e95456 100644 --- a/src/client/application/geary-controller.vala +++ b/src/client/application/geary-controller.vala @@ -148,6 +148,9 @@ public class GearyController : Geary.BaseObject { private GLib.Cancellable? open_cancellable = null; private Folks.IndividualAggregator? folks = null; + + private Canberra.Context? sound_context = null; + private Geary.Folder? current_folder = null; private Cancellable cancellable_folder = new Cancellable(); private Cancellable cancellable_search = new Cancellable(); @@ -273,6 +276,8 @@ public class GearyController : Geary.BaseObject { error("Error loading web resources: %s", err.message); } + Canberra.Context.create(out this.sound_context); + this.folks = Folks.IndividualAggregator.dup(); if (!this.folks.is_prepared) { // Do this in the background since it can take a long time @@ -447,6 +452,7 @@ public class GearyController : Geary.BaseObject { } // Release monitoring early so held resources can be freed up + this.sound_context = null; this.notifications = null; this.new_messages_indicator = null; this.unity_launcher = null; @@ -2621,7 +2627,7 @@ public class GearyController : Geary.BaseObject { ).printf(Util.Email.to_short_recipient_display(rfc822.to)); InAppNotification notification = new InAppNotification(message); this.main_window.add_notification(notification); - this.notifications.play_sound("message-sent-email"); + this.play_sound("message-sent-email"); } private void on_conversation_view_added(ConversationListBox list) { @@ -2858,6 +2864,12 @@ public class GearyController : Geary.BaseObject { return false; } + public void play_sound(string sound) { + if (this.application.config.play_sounds) { + this.sound_context.play(0, Canberra.PROP_EVENT_ID, sound); + } + } + private void on_account_available(Geary.AccountInformation info) { Geary.Account? account = null; try { diff --git a/src/client/notification/notification-desktop.vala b/src/client/notification/notification-desktop.vala index 1dfc9713..961fcd21 100644 --- a/src/client/notification/notification-desktop.vala +++ b/src/client/notification/notification-desktop.vala @@ -16,15 +16,6 @@ public class Notification.Desktop : Geary.BaseObject { private const string ARRIVED_ID = "email-arrived"; private const string ERROR_ID = "error"; - - private static void init_sound() { - if (Desktop.sound_context == null) { - Canberra.Context.create(out sound_context); - } - } - - private static Canberra.Context? sound_context = null; - private weak NewMessagesMonitor monitor; private weak GearyApplication application; private GLib.Notification? current_notification = null; @@ -40,7 +31,6 @@ public class Notification.Desktop : Geary.BaseObject { this.monitor = monitor; this.application = application; this.load_cancellable = load_cancellable; - init_sound(); this.monitor.add_required_fields(REQUIRED_FIELDS); this.monitor.new_messages_arrived.connect(on_new_messages_arrived); @@ -51,14 +41,6 @@ public class Notification.Desktop : Geary.BaseObject { this.monitor.new_messages_arrived.disconnect(on_new_messages_arrived); } - public void play_sound(string sound) { - if (this.application.config.play_sounds) { - Desktop.sound_context.play( - 0, Canberra.PROP_EVENT_ID, sound - ); - } - } - public void clear_arrived_notification() { this.application.withdraw_notification(ARRIVED_ID); this.current_notification = null; @@ -70,7 +52,7 @@ public class Notification.Desktop : Geary.BaseObject { // but it means in the future, a more robust system will be needed.) if (this.error_notification == null) { this.error_notification = issue_notification( - ERROR_ID, summary, body, null + ERROR_ID, summary, body ); } } @@ -171,26 +153,19 @@ public class Notification.Desktop : Geary.BaseObject { private void issue_current_notification(string summary, string body) { // only one outstanding notification at a time clear_arrived_notification(); - this.current_notification = issue_notification( - ARRIVED_ID, summary, body, "message-new_email" + this.arrived_notification = issue_notification( + ARRIVED_ID, summary, body ); } private GLib.Notification issue_notification(string id, string summary, - string body, - string? sound) { + string body) { GLib.Notification notification = new GLib.Notification(summary); notification.set_body(body); notification.set_icon( new GLib.ThemedIcon("%s-symbolic".printf(GearyApplication.APP_ID)) ); - //notification.set_default_action("app.activate"); - - if (sound != null) { - play_sound(sound); - } - this.application.send_notification(id, notification); return notification; }