Don't play sounds when issuing a notifciation
We can't reliably play a sound when issuing a notification, since they maybe disabled by the desktop. So let the desktop's notification system handle that. As a result, move sound code to the controller since the only place it is used now is when sending email.
This commit is contained in:
parent
3701aa0c30
commit
f269e552ae
2 changed files with 17 additions and 30 deletions
|
|
@ -148,6 +148,9 @@ public class GearyController : Geary.BaseObject {
|
||||||
private GLib.Cancellable? open_cancellable = null;
|
private GLib.Cancellable? open_cancellable = null;
|
||||||
|
|
||||||
private Folks.IndividualAggregator? folks = null;
|
private Folks.IndividualAggregator? folks = null;
|
||||||
|
|
||||||
|
private Canberra.Context? sound_context = null;
|
||||||
|
|
||||||
private Geary.Folder? current_folder = null;
|
private Geary.Folder? current_folder = null;
|
||||||
private Cancellable cancellable_folder = new Cancellable();
|
private Cancellable cancellable_folder = new Cancellable();
|
||||||
private Cancellable cancellable_search = 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);
|
error("Error loading web resources: %s", err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Canberra.Context.create(out this.sound_context);
|
||||||
|
|
||||||
this.folks = Folks.IndividualAggregator.dup();
|
this.folks = Folks.IndividualAggregator.dup();
|
||||||
if (!this.folks.is_prepared) {
|
if (!this.folks.is_prepared) {
|
||||||
// Do this in the background since it can take a long time
|
// 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
|
// Release monitoring early so held resources can be freed up
|
||||||
|
this.sound_context = null;
|
||||||
this.notifications = null;
|
this.notifications = null;
|
||||||
this.new_messages_indicator = null;
|
this.new_messages_indicator = null;
|
||||||
this.unity_launcher = null;
|
this.unity_launcher = null;
|
||||||
|
|
@ -2621,7 +2627,7 @@ public class GearyController : Geary.BaseObject {
|
||||||
).printf(Util.Email.to_short_recipient_display(rfc822.to));
|
).printf(Util.Email.to_short_recipient_display(rfc822.to));
|
||||||
InAppNotification notification = new InAppNotification(message);
|
InAppNotification notification = new InAppNotification(message);
|
||||||
this.main_window.add_notification(notification);
|
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) {
|
private void on_conversation_view_added(ConversationListBox list) {
|
||||||
|
|
@ -2858,6 +2864,12 @@ public class GearyController : Geary.BaseObject {
|
||||||
return false;
|
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) {
|
private void on_account_available(Geary.AccountInformation info) {
|
||||||
Geary.Account? account = null;
|
Geary.Account? account = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -16,15 +16,6 @@ public class Notification.Desktop : Geary.BaseObject {
|
||||||
private const string ARRIVED_ID = "email-arrived";
|
private const string ARRIVED_ID = "email-arrived";
|
||||||
private const string ERROR_ID = "error";
|
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 NewMessagesMonitor monitor;
|
||||||
private weak GearyApplication application;
|
private weak GearyApplication application;
|
||||||
private GLib.Notification? current_notification = null;
|
private GLib.Notification? current_notification = null;
|
||||||
|
|
@ -40,7 +31,6 @@ public class Notification.Desktop : Geary.BaseObject {
|
||||||
this.monitor = monitor;
|
this.monitor = monitor;
|
||||||
this.application = application;
|
this.application = application;
|
||||||
this.load_cancellable = load_cancellable;
|
this.load_cancellable = load_cancellable;
|
||||||
init_sound();
|
|
||||||
|
|
||||||
this.monitor.add_required_fields(REQUIRED_FIELDS);
|
this.monitor.add_required_fields(REQUIRED_FIELDS);
|
||||||
this.monitor.new_messages_arrived.connect(on_new_messages_arrived);
|
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);
|
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() {
|
public void clear_arrived_notification() {
|
||||||
this.application.withdraw_notification(ARRIVED_ID);
|
this.application.withdraw_notification(ARRIVED_ID);
|
||||||
this.current_notification = null;
|
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.)
|
// but it means in the future, a more robust system will be needed.)
|
||||||
if (this.error_notification == null) {
|
if (this.error_notification == null) {
|
||||||
this.error_notification = issue_notification(
|
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) {
|
private void issue_current_notification(string summary, string body) {
|
||||||
// only one outstanding notification at a time
|
// only one outstanding notification at a time
|
||||||
clear_arrived_notification();
|
clear_arrived_notification();
|
||||||
this.current_notification = issue_notification(
|
this.arrived_notification = issue_notification(
|
||||||
ARRIVED_ID, summary, body, "message-new_email"
|
ARRIVED_ID, summary, body
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GLib.Notification issue_notification(string id,
|
private GLib.Notification issue_notification(string id,
|
||||||
string summary,
|
string summary,
|
||||||
string body,
|
string body) {
|
||||||
string? sound) {
|
|
||||||
GLib.Notification notification = new GLib.Notification(summary);
|
GLib.Notification notification = new GLib.Notification(summary);
|
||||||
notification.set_body(body);
|
notification.set_body(body);
|
||||||
notification.set_icon(
|
notification.set_icon(
|
||||||
new GLib.ThemedIcon("%s-symbolic".printf(GearyApplication.APP_ID))
|
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);
|
this.application.send_notification(id, notification);
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue