[gnome-shell] messageTray: Clean up _updateState for notifications



commit b6499e524856f7976dcb8b2f0c773425c940db1f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Aug 1 23:07:59 2013 -0400

    messageTray: Clean up _updateState for notifications
    
    _updateState has a lot of variables that sort of gunk up the
    code and make it more unreadable than need be. Clean up the logic
    a lot by moving those variables into the places that they actually
    matter, renaming them to remove prefixes, and remove some conditions
    that are always met.

 js/ui/messageTray.js |   48 +++++++++++++++++++++++-------------------------
 1 files changed, 23 insertions(+), 25 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 12597ab..8730c97 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -2236,39 +2236,37 @@ const MessageTray = new Lang.Class({
     // _updateState() figures out what (if anything) needs to be done
     // at the present time.
     _updateState: function() {
-        // Notifications
-        let notificationQueue = this._notificationQueue.filter(function(n) {
+        // Filter out acknowledged notifications.
+        this._notificationQueue = this._notificationQueue.filter(function(n) {
             return !n.acknowledged;
         });
-        let hasNotifications = Main.sessionMode.hasNotifications;
 
-        this._notificationQueue = notificationQueue;
-        let notificationUrgent = notificationQueue.length > 0 && notificationQueue[0].urgency == 
Urgency.CRITICAL;
-        let notificationForFeedback = notificationQueue.length > 0 && notificationQueue[0].forFeedback;
-        let notificationsLimited = this._busy || Main.layoutManager.bottomMonitor.inFullscreen;
-        let notificationsPending = notificationQueue.length > 0 && (!notificationsLimited || 
notificationUrgent || notificationForFeedback) && hasNotifications;
-        let nextNotification = notificationQueue.length > 0 ? notificationQueue[0] : null;
-        let notificationPinned = this._pointerInNotification && !this._notificationRemoved;
-        let notificationExpanded = this._notification && this._notification.expanded;
-        let notificationExpired = (this._userActiveWhileNotificationShown &&
-                                   this._notificationTimeoutId == 0 &&
-                                   !(this._notification && this._notification.urgency == Urgency.CRITICAL) &&
-                                   !(this._notification && this._notification.focused) &&
-                                   !this._pointerInNotification);
-        let notificationLockedOut = !hasNotifications && this._notification;
-        let notificationMustClose = (this._notificationRemoved || notificationLockedOut || 
notificationExpired || this._traySummoned);
-        let canShowNotification = notificationsPending && this._trayState == State.HIDDEN && 
!this._traySummoned;
+        let hasNotifications = Main.sessionMode.hasNotifications;
 
         if (this._notificationState == State.HIDDEN) {
-            if (canShowNotification)
-                this._showNotification();
+            let shouldShowNotification = (hasNotifications && this._trayState == State.HIDDEN && 
!this._traySummoned);
+            let nextNotification = this._notificationQueue[0] || null;
+            if (shouldShowNotification && nextNotification) {
+                let limited = this._busy || Main.layoutManager.bottomMonitor.inFullscreen;
+                let showNextNotification = (!limited || nextNotification.forFeedback || 
nextNotification.urgency == Urgency.CRITICAL);
+                if (showNextNotification)
+                    this._showNotification();
+            }
         } else if (this._notificationState == State.SHOWN) {
-            if (notificationMustClose) {
-                let animate = !(this._notificationRemoved || notificationLockedOut);
+            let pinned = this._pointerInNotification && !this._notificationRemoved;
+            let expired = (this._userActiveWhileNotificationShown &&
+                           this._notificationTimeoutId == 0 &&
+                           !(this._notification.urgency == Urgency.CRITICAL) &&
+                           !this._notification.focused &&
+                           !this._pointerInNotification);
+            let mustClose = (this._notificationRemoved || !hasNotifications || expired || 
this._traySummoned);
+
+            if (mustClose) {
+                let animate = hasNotifications && !this._notificationRemoved;
                 this._hideNotification(animate);
-            } else if (notificationPinned && !notificationExpanded) {
+            } else if (pinned && !this._notification.expanded) {
                 this._expandNotification(false);
-            } else if (notificationPinned) {
+            } else if (pinned) {
                 this._ensureNotificationFocused();
             }
         }


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