[gnome-shell/wip/fmuellner/dont-disturb: 33/33] dateMenu: Indicate when do-not-disturb is on



commit 62c649604c108ca748f977e2d80fc69ead6069a6
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jan 17 17:26:08 2020 +0100

    dateMenu: Indicate when do-not-disturb is on
    
    When do-not-disturb is enabled, non-critical notifications will not
    be shown as banners. It therefore makes sense to indicate that state
    to the user, so they don't accidentally miss notifications.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/239

 js/ui/dateMenu.js | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js
index 5542d8f7ce..70762f9ab7 100644
--- a/js/ui/dateMenu.js
+++ b/js/ui/dateMenu.js
@@ -432,7 +432,6 @@ var MessagesIndicator = GObject.registerClass(
 class MessagesIndicator extends St.Icon {
     _init() {
         super._init({
-            icon_name: 'message-indicator-symbolic',
             icon_size: 16,
             visible: false,
             y_expand: true,
@@ -440,6 +439,13 @@ class MessagesIndicator extends St.Icon {
         });
 
         this._sources = [];
+        this._count = 0;
+        this._doNotDisturb = false;
+
+        this._settings = new Gio.Settings({
+            schema_id: 'org.gnome.desktop.notifications',
+        });
+        this._settings.connect('changed::show-banners', this._sync.bind(this));
 
         Main.messageTray.connect('source-added', this._onSourceAdded.bind(this));
         Main.messageTray.connect('source-removed', this._onSourceRemoved.bind(this));
@@ -447,6 +453,11 @@ class MessagesIndicator extends St.Icon {
 
         let sources = Main.messageTray.getSources();
         sources.forEach(source => this._onSourceAdded(null, source));
+
+        this.connect('destroy', () => {
+            this._settings.run_dispose();
+            this._settings = null;
+        });
     }
 
     _onSourceAdded(tray, source) {
@@ -463,9 +474,17 @@ class MessagesIndicator extends St.Icon {
     _updateCount() {
         let count = 0;
         this._sources.forEach(source => (count += source.unseenCount));
-        count -= Main.messageTray.queueCount;
+        this._count = count - Main.messageTray.queueCount;
 
-        this.visible = count > 0;
+        this._sync();
+    }
+
+    _sync() {
+        let doNotDisturb = !this._settings.get_boolean('show-banners');
+        this.icon_name = doNotDisturb
+            ? 'notifications-disabled-symbolic'
+            : 'message-indicator-symbolic';
+        this.visible = doNotDisturb || this._count > 0;
     }
 });
 


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