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.
This commit is contained in:
parent
3cb809b444
commit
b6499e5248
@ -2236,39 +2236,37 @@ const MessageTray = new Lang.Class({
|
|||||||
// _updateState() figures out what (if anything) needs to be done
|
// _updateState() figures out what (if anything) needs to be done
|
||||||
// at the present time.
|
// at the present time.
|
||||||
_updateState: function() {
|
_updateState: function() {
|
||||||
// Notifications
|
// Filter out acknowledged notifications.
|
||||||
let notificationQueue = this._notificationQueue.filter(function(n) {
|
this._notificationQueue = this._notificationQueue.filter(function(n) {
|
||||||
return !n.acknowledged;
|
return !n.acknowledged;
|
||||||
});
|
});
|
||||||
|
|
||||||
let hasNotifications = Main.sessionMode.hasNotifications;
|
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;
|
|
||||||
|
|
||||||
if (this._notificationState == State.HIDDEN) {
|
if (this._notificationState == State.HIDDEN) {
|
||||||
if (canShowNotification)
|
let shouldShowNotification = (hasNotifications && this._trayState == State.HIDDEN && !this._traySummoned);
|
||||||
this._showNotification();
|
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) {
|
} else if (this._notificationState == State.SHOWN) {
|
||||||
if (notificationMustClose) {
|
let pinned = this._pointerInNotification && !this._notificationRemoved;
|
||||||
let animate = !(this._notificationRemoved || notificationLockedOut);
|
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);
|
this._hideNotification(animate);
|
||||||
} else if (notificationPinned && !notificationExpanded) {
|
} else if (pinned && !this._notification.expanded) {
|
||||||
this._expandNotification(false);
|
this._expandNotification(false);
|
||||||
} else if (notificationPinned) {
|
} else if (pinned) {
|
||||||
this._ensureNotificationFocused();
|
this._ensureNotificationFocused();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user