[gnome-clocks] application: Withdraw system notifications on exit



commit be09d98c476b579f831cfde44f68ec7840f2c2e9
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Feb 1 12:27:06 2017 +0100

    application: Withdraw system notifications on exit
    
    This patch keeps track of the system notifications as they appear
    and withdraws them when the application quits.
    
    The HIG[0] says that "Notifications in GNOME 3 persist after they
    have been initially displayed. It is therefore important to remove
    notification messages that are no longer relevant to the user."
    
    [0] https://developer.gnome.org/hig/stable/notifications.html.en
    
    https://bugzilla.gnome.org/show_bug.cgi?id=776043

 src/alarm.vala       |    4 ++--
 src/application.vala |   18 ++++++++++++++++++
 src/timer.vala       |    4 ++--
 3 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/src/alarm.vala b/src/alarm.vala
index 257e314..f57291a 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -159,8 +159,8 @@ private class Item : Object, ContentItem {
     }
 
     public virtual signal void ring () {
-        var app = GLib.Application.get_default ();
-        app.send_notification (null, notification);
+        var app = GLib.Application.get_default () as Clocks.Application;
+        app.send_notification ("alarm-clock-elapsed", notification);
         bell.ring ();
     }
 
diff --git a/src/application.vala b/src/application.vala
index 9a85d76..f9374d8 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -34,6 +34,7 @@ public class Application : Gtk.Application {
     private SearchProvider search_provider;
     private uint search_provider_id = 0;
     private Window window;
+    private List<string> system_notifications;
 
     private void ensure_window () {
         if (window == null) {
@@ -58,6 +59,8 @@ public class Application : Gtk.Application {
             window.show_world ();
             window.present_with_time (timestamp);
         });
+
+        system_notifications = new List<string> ();
     }
 
     public override bool dbus_register (DBusConnection connection, string object_path) {
@@ -131,6 +134,21 @@ public class Application : Gtk.Application {
         }
     }
 
+    public new void send_notification (string notification_id, GLib.Notification notification) {
+        base.send_notification (notification_id, notification);
+
+        system_notifications.append (notification_id);
+    }
+
+    public override void shutdown () {
+        base.shutdown ();
+
+        // Withdraw all system notifications
+        foreach (var notification in system_notifications) {
+            withdraw_notification (notification);
+        }
+    }
+
     void on_quit_activate () {
         quit ();
     }
diff --git a/src/timer.vala b/src/timer.vala
index 8d7e23d..fbe8536 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -135,8 +135,8 @@ public class Face : Gtk.Stack, Clocks.Clock {
     }
 
     public virtual signal void ring () {
-        var app = GLib.Application.get_default ();
-        app.send_notification (null, notification);
+        var app = GLib.Application.get_default () as Clocks.Application;
+        app.send_notification ("timer-is-up", notification);
         bell.ring_once ();
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]