From 7625f1e81860be0166e608bcdaa955bf63f77578 Mon Sep 17 00:00:00 2001 From: Rick Calixte <10281587+rcalixte@users.noreply.github.com> Date: Sun, 27 Nov 2022 18:20:26 -0500 Subject: [PATCH] Fix whitespace --- js/ui/messageTray.js | 331 ++++++++++++++++++++++++------------------- 1 file changed, 184 insertions(+), 147 deletions(-) diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 3599500338..ad724edc51 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -32,10 +32,10 @@ const NOTIFICATION_IMAGE_SIZE = 125; const NOTIFICATION_IMAGE_OPACITY = 230; // 0 - 255 var State = { - HIDDEN: 0, + HIDDEN: 0, SHOWING: 1, - SHOWN: 2, - HIDING: 3 + SHOWN: 2, + HIDING: 3 }; // These reasons are useful when we destroy the notifications received through @@ -73,7 +73,7 @@ function _fixMarkup(text, allowMarkup) { try { Pango.parse_markup(_text, -1, ''); return _text; - } catch (e) {} + } catch (e) { } } // !allowMarkup, or invalid markup @@ -85,12 +85,12 @@ function URLHighlighter(text, lineWrap, allowMarkup) { } URLHighlighter.prototype = { - _init: function(text, lineWrap, allowMarkup) { + _init: function (text, lineWrap, allowMarkup) { if (!text) text = ''; this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter' }); this._linkColor = '#ccccff'; - this.actor.connect('style-changed', Lang.bind(this, function() { + this.actor.connect('style-changed', Lang.bind(this, function () { let [hasColor, color] = this.actor.get_theme_node().lookup_color('link-color', false); if (hasColor) { let linkColor = color.to_string().substr(0, 7); @@ -107,7 +107,7 @@ URLHighlighter.prototype = { } this.setMarkup(text, allowMarkup); - this.actor.connect('button-press-event', Lang.bind(this, function(actor, event) { + this.actor.connect('button-press-event', Lang.bind(this, function (actor, event) { // Don't try to URL highlight when invisible. // The MessageTray doesn't actually hide us, so // we need to check for paint opacities as well. @@ -139,7 +139,7 @@ URLHighlighter.prototype = { } return false; })); - this.actor.connect('motion-event', Lang.bind(this, function(actor, event) { + this.actor.connect('motion-event', Lang.bind(this, function (actor, event) { if (!actor.visible || actor.get_paint_opacity() == 0) return false; @@ -153,7 +153,7 @@ URLHighlighter.prototype = { } return false; })); - this.actor.connect('leave-event', Lang.bind(this, function() { + this.actor.connect('leave-event', Lang.bind(this, function () { if (!this.actor.visible || this.actor.get_paint_opacity() == 0) return; @@ -164,7 +164,7 @@ URLHighlighter.prototype = { })); }, - setMarkup: function(text, allowMarkup) { + setMarkup: function (text, allowMarkup) { text = text ? _fixMarkup(text, allowMarkup) : ''; this._text = text; @@ -174,7 +174,7 @@ URLHighlighter.prototype = { this._highlightUrls(); }, - _highlightUrls: function() { + _highlightUrls: function () { // text here contain markup let urls = Util.findUrls(this._text); let markup = ''; @@ -189,7 +189,7 @@ URLHighlighter.prototype = { this.actor.clutter_text.set_markup(markup); }, - _findUrlAtPos: function(event) { + _findUrlAtPos: function (event) { if (!this._urls.length) return -1; @@ -198,7 +198,7 @@ URLHighlighter.prototype = { let ct = this.actor.clutter_text; [success, x, y] = ct.transform_stage_point(x, y); if (success && x >= 0 && x <= ct.width - && y >= 0 && y <= ct.height) { + && y >= 0 && y <= ct.height) { let pos = ct.coords_to_position(x, y); for (let i = 0; i < this._urls.length; i++) { let url = this._urls[i] @@ -267,8 +267,10 @@ var Notification = class Notification { this.actor.connect('clicked', () => this._onClicked()); this.actor.connect('destroy', () => this._onDestroy()); - this._table = new St.Table({ name: 'notification', - reactive: true }); + this._table = new St.Table({ + name: 'notification', + reactive: true + }); this.actor.set_child(this._table); this._buttonFocusManager = St.FocusManager.get_for_stage(global.stage); @@ -276,14 +278,18 @@ var Notification = class Notification { // the banner box is now just a simple vbox. // The first line should have the time, and the second the title. // Time only shown inside message tray. - this._bannerBox = new St.BoxLayout({ vertical: true, - style: "spacing: 4px" }); - this._table.add(this._bannerBox, { row: 0, - col: 1, - col_span: 2, - x_expand: false, - y_expand: false, - y_fill: false }); + this._bannerBox = new St.BoxLayout({ + vertical: true, + style: "spacing: 4px" + }); + this._table.add(this._bannerBox, { + row: 0, + col: 1, + col_span: 2, + x_expand: false, + y_expand: false, + y_fill: false + }); this._timeLabel = new St.Label({ show_on_set_parent: false }); this._titleLabel = new St.Label(); @@ -295,24 +301,30 @@ var Notification = class Notification { // This is an empty cell that overlaps with this._bannerBox cell to ensure // that this._bannerBox cell expands horizontally, while not forcing the // this._imageBin that is also in col: 2 to expand horizontally. - this._table.add(new St.Bin(), { row: 0, - col: 2, - y_expand: false, - y_fill: false }); + this._table.add(new St.Bin(), { + row: 0, + col: 2, + y_expand: false, + y_fill: false + }); // notification dismiss button - let icon = new St.Icon({ icon_name: 'window-close', - icon_type: St.IconType.SYMBOLIC, - icon_size: 16 }); + let icon = new St.Icon({ + icon_name: 'window-close', + icon_type: St.IconType.SYMBOLIC, + icon_size: 16 + }); let closeButton = new St.Button({ child: icon, opacity: 128 }); closeButton.connect('clicked', Lang.bind(this, this.destroy)); - closeButton.connect('notify::hover', function() { closeButton.opacity = closeButton.hover ? 255 : 128; }); - this._table.add(closeButton, { row: 0, - col: 3, - x_expand: false, - y_expand: false, - y_fill: false, - y_align: St.Align.START }); + closeButton.connect('notify::hover', function () { closeButton.opacity = closeButton.hover ? 255 : 128; }); + this._table.add(closeButton, { + row: 0, + col: 3, + x_expand: false, + y_expand: false, + y_fill: false, + y_align: St.Align.START + }); // set icon, title, body this.update(title, body, params); @@ -333,10 +345,12 @@ var Notification = class Notification { update(title, body, params) { this._timestamp = new Date(); this._inNotificationBin = false; - params = Params.parse(params, { icon: null, - titleMarkup: false, - bodyMarkup: false, - silent: false }); + params = Params.parse(params, { + icon: null, + titleMarkup: false, + bodyMarkup: false, + silent: false + }); this.silent = params.silent; @@ -347,16 +361,18 @@ var Notification = class Notification { if (!this._icon) { this._icon = params.icon || this.source.createNotificationIcon(); - this._table.add(this._icon, { row: 0, - col: 0, - x_expand: false, - y_expand: false, - y_fill: false, - y_align: St.Align.START }); + this._table.add(this._icon, { + row: 0, + col: 0, + x_expand: false, + y_expand: false, + y_fill: false, + y_align: St.Align.START + }); } // title: strip newlines, escape or validate markup, add bold markup - if (typeof(title) === "string") { + if (typeof (title) === "string") { this.title = _fixMarkup(title.replace(/\n/g, ' '), params.titleMarkup); } else { this.title = ""; @@ -401,17 +417,22 @@ var Notification = class Notification { * ideally, this should only be disabled when the notification is in the tray and there are * many notifications. */ - this._scrollArea = new St.ScrollView({ name: 'notification-scrollview', - vscrollbar_policy: St.PolicyType.NEVER, - hscrollbar_policy: St.PolicyType.NEVER, - enable_mouse_scrolling: false/*, + this._scrollArea = new St.ScrollView({ + name: 'notification-scrollview', + vscrollbar_policy: St.PolicyType.NEVER, + hscrollbar_policy: St.PolicyType.NEVER, + enable_mouse_scrolling: false/*, style_class: 'vfade'*/ }); - this._table.add(this._scrollArea, { row: 1, - col: 2 }); + this._table.add(this._scrollArea, { + row: 1, + col: 2 + }); - let content = new St.BoxLayout({ name: 'notification-body', - vertical: true }); + let content = new St.BoxLayout({ + name: 'notification-body', + vertical: true + }); this._scrollArea.add_actor(content); // body label @@ -435,12 +456,12 @@ var Notification = class Notification { this._icon.visible = visible; } - /** - * scrollTo: - * @side (St.Side): St.Side.TOP or St.Side.BOTTOM - * - * Scrolls the content area (if scrollable) to the indicated edge - */ + /** + * scrollTo: + * @side (St.Side): St.Side.TOP or St.Side.BOTTOM + * + * Scrolls the content area (if scrollable) to the indicated edge + */ scrollTo(side) { if (!this._scrollArea) return; @@ -465,11 +486,15 @@ var Notification = class Notification { } if (this._scrollArea) - this._table.child_set(this._scrollArea, { col: this._imageBin ? 2 : 1, - col_span: this._imageBin ? 2 : 3 }); + this._table.child_set(this._scrollArea, { + col: this._imageBin ? 2 : 1, + col_span: this._imageBin ? 2 : 3 + }); if (this._actionArea) - this._table.child_set(this._actionArea, { col: this._imageBin ? 2 : 1, - col_span: this._imageBin ? 2 : 3 }); + this._table.child_set(this._actionArea, { + col: this._imageBin ? 2 : 1, + col_span: this._imageBin ? 2 : 3 + }); } setImage(image) { @@ -477,15 +502,19 @@ var Notification = class Notification { this.unsetImage(); if (!image) return; - this._imageBin = new St.Bin({ child: image, - opacity: NOTIFICATION_IMAGE_OPACITY }); - this._table.add(this._imageBin, { row: 1, - col: 1, - row_span: 2, - x_expand: false, - y_expand: false, - x_fill: false, - y_fill: false }); + this._imageBin = new St.Bin({ + child: image, + opacity: NOTIFICATION_IMAGE_OPACITY + }); + this._table.add(this._imageBin, { + row: 1, + col: 1, + row_span: 2, + x_expand: false, + y_expand: false, + x_fill: false, + y_fill: false + }); this._updateLayout(); } @@ -512,14 +541,16 @@ var Notification = class Notification { addButton(id, label) { if (!this._actionArea) { this._actionArea = new St.BoxLayout({ name: 'notification-actions' }); - this._table.add(this._actionArea, { row: 2, - col: 1, - col_span: 3, - x_expand: true, - y_expand: false, - x_fill: true, - y_fill: false, - x_align: St.Align.START }); + this._table.add(this._actionArea, { + row: 2, + col: 1, + col_span: 3, + x_expand: true, + y_expand: false, + x_fill: true, + y_fill: false, + x_align: St.Align.START + }); } let button = new St.Button({ can_focus: true }); @@ -619,11 +650,13 @@ Source.prototype = { ICON_SIZE: 24, MAX_NOTIFICATIONS: 10, - _init: function(title) { + _init: function (title) { this.title = title; - this.actor = new St.Bin({ x_fill: true, - y_fill: true }); + this.actor = new St.Bin({ + x_fill: true, + y_fill: true + }); this.actor.connect('destroy', () => { this._actorDestroyed = true }); this._actorDestroyed = false; @@ -633,7 +666,7 @@ Source.prototype = { this.notifications = []; }, - _updateCount: function() { + _updateCount: function () { let count = this.notifications.length; if (count > this.MAX_NOTIFICATIONS) { let oldestNotif = this.notifications.shift(); @@ -641,24 +674,24 @@ Source.prototype = { } }, - setTransient: function(isTransient) { + setTransient: function (isTransient) { this.isTransient = isTransient; }, // Called to create a new icon actor (of size this.ICON_SIZE). // Must be overridden by the subclass if you do not pass icons // explicitly to the Notification() constructor. - createNotificationIcon: function() { + createNotificationIcon: function () { throw new Error('no implementation of createNotificationIcon in ' + this); }, // Unlike createNotificationIcon, this always returns the same actor; // there is only one summary icon actor for a Source. - getSummaryIcon: function() { + getSummaryIcon: function () { return this.actor; }, - pushNotification: function(notification) { + pushNotification: function (notification) { if (this.notifications.indexOf(notification) < 0) { this.notifications.push(notification); this.emit('notification-added', notification); @@ -678,36 +711,36 @@ Source.prototype = { this._updateCount(); }, - notify: function(notification) { + notify: function (notification) { this.pushNotification(notification); this.emit('notify', notification); }, - destroy: function(reason) { + destroy: function (reason) { this.emit('destroy', reason); }, //// Protected methods //// // The subclass must call this at least once to set the summary icon. - _setSummaryIcon: function(icon) { + _setSummaryIcon: function (icon) { if (this.actor.child) this.actor.child.destroy(); this.actor.child = icon; }, // Default implementation is to do nothing, but subclasses can override - open: function(notification) { + open: function (notification) { }, - destroyNonResidentNotifications: function() { + destroyNonResidentNotifications: function () { for (let i = this.notifications.length - 1; i >= 0; i--) if (!this.notifications[i].resident) this.notifications[i].destroy(); }, // Default implementation is to destroy this source, but subclasses can override - _lastNotificationRemoved: function() { + _lastNotificationRemoved: function () { this.destroy(); } }; @@ -718,8 +751,8 @@ function MessageTray() { } MessageTray.prototype = { - _init: function() { - this._presence = new GnomeSession.Presence(Lang.bind(this, function(proxy, error) { + _init: function () { + this._presence = new GnomeSession.Presence(Lang.bind(this, function (proxy, error) { this._onStatusChanged(proxy.status); })); @@ -727,7 +760,7 @@ MessageTray.prototype = { this._busy = false; this._backFromAway = false; - this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) { + this._presence.connectSignal('StatusChanged', Lang.bind(this, function (proxy, senderName, [status]) { this._onStatusChanged(status); })); @@ -745,20 +778,20 @@ MessageTray.prototype = { this._sources = []; Main.layoutManager.addChrome(this._notificationBin); - // Settings - this.settings = new Gio.Settings({ schema_id: "org.cinnamon.desktop.notifications" }) - function setting(self, source, camelCase, dashed) { - function updater() { self[camelCase] = source.get_boolean(dashed); } - source.connect('changed::'+dashed, updater); - updater(); - } - setting(this, this.settings, "_notificationsEnabled", "display-notifications"); + // Settings + this.settings = new Gio.Settings({ schema_id: "org.cinnamon.desktop.notifications" }); + function setting(self, source, camelCase, dashed) { + function updater() { self[camelCase] = source.get_boolean(dashed); } + source.connect('changed::' + dashed, updater); + updater(); + } + setting(this, this.settings, "_notificationsEnabled", "display-notifications"); this.bottomPosition = this.settings.get_boolean("bottom-notifications"); this.settings.connect("changed::bottom-notifications", () => { this.bottomPosition = this.settings.get_boolean("bottom-notifications"); }); - let updateLockState = Lang.bind(this, function() { + let updateLockState = Lang.bind(this, function () { if (this._locked) { this._unlock(); } else { @@ -772,15 +805,15 @@ MessageTray.prototype = { Main.expo.connect('hiding', updateLockState); }, - contains: function(source) { + contains: function (source) { return this._getSourceIndex(source) >= 0; }, - _getSourceIndex: function(source) { + _getSourceIndex: function (source) { return this._sources.indexOf(source); }, - add: function(source) { + add: function (source) { if (this.contains(source)) { log('Trying to re-add source ' + source.title); return; @@ -791,7 +824,7 @@ MessageTray.prototype = { source.connect('destroy', Lang.bind(this, this._onSourceDestroy)); }, - _onSourceDestroy: function(source) { + _onSourceDestroy: function (source) { let index = this._getSourceIndex(source); if (index == -1) return; @@ -810,7 +843,7 @@ MessageTray.prototype = { this._updateState(); }, - _onNotificationDestroy: function(notification) { + _onNotificationDestroy: function (notification) { if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) { this._updateNotificationTimeout(0); this._notificationRemoved = true; @@ -824,18 +857,18 @@ MessageTray.prototype = { this._notificationQueue.splice(index, 1); }, - _lock: function() { + _lock: function () { this._locked = true; }, - _unlock: function() { + _unlock: function () { if (!this._locked) return; this._locked = false; this._updateState(); }, - _onNotify: function(source, notification) { + _onNotify: function (source, notification) { if (this._notification == notification) { // If a notification that is being shown is updated, we update // how it is shown and extend the time until it auto-hides. @@ -844,16 +877,16 @@ MessageTray.prototype = { this._updateShowingNotification(); } else if (this._notificationQueue.indexOf(notification) < 0) { notification.connect('destroy', - Lang.bind(this, this._onNotificationDestroy)); + Lang.bind(this, this._onNotificationDestroy)); this._notificationQueue.push(notification); - this._notificationQueue.sort(function(notification1, notification2) { + this._notificationQueue.sort(function (notification1, notification2) { return (notification2.urgency - notification1.urgency); }); } this._updateState(); }, - _onStatusChanged: function(status) { + _onStatusChanged: function (status) { this._backFromAway = (this._userStatus == GnomeSession.PresenceStatus.IDLE && this._userStatus != status); this._userStatus = status; @@ -875,15 +908,15 @@ MessageTray.prototype = { // event handlers merely update variables and // _updateState() figures out what (if anything) needs to be done // at the present time. - _updateState: function() { + _updateState: function () { // Notifications let notificationUrgent = this._notificationQueue.length > 0 && this._notificationQueue[0].urgency == Urgency.CRITICAL; let notificationsPending = this._notificationQueue.length > 0 && (!this._busy || notificationUrgent); let notificationExpired = (this._notificationTimeoutId == 0 && - !(this._notification && this._notification.urgency == Urgency.CRITICAL) && - !this._locked - ) || this._notificationRemoved; + !(this._notification && this._notification.urgency == Urgency.CRITICAL) && + !this._locked + ) || this._notificationRemoved; let canShowNotification = notificationsPending && this._notificationsEnabled; if (this._notificationState == State.HIDDEN) { @@ -907,7 +940,7 @@ MessageTray.prototype = { } }, - _tween: function(actor, statevar, value, params) { + _tween: function (actor, statevar, value, params) { let onComplete = params.onComplete; let onCompleteScope = params.onCompleteScope; let onCompleteParams = params.onCompleteParams; @@ -922,14 +955,14 @@ MessageTray.prototype = { this[statevar] = valuing; }, - _tweenComplete: function(statevar, value, onComplete, onCompleteScope, onCompleteParams) { + _tweenComplete: function (statevar, value, onComplete, onCompleteScope, onCompleteParams) { this[statevar] = value; if (onComplete) onComplete.apply(onCompleteScope, onCompleteParams); this._updateState(); }, - _showNotification: function() { + _showNotification: function () { this._notification = this._notificationQueue.shift(); if (this._notification.actor._parent_container) { this._notification.actor._parent_container.remove_actor(this._notification.actor); @@ -1013,17 +1046,19 @@ MessageTray.prototype = { this._lastSeenMouseDistance = Math.abs(this._notificationBin.y - y); }, - _updateShowingNotification: function() { + _updateShowingNotification: function () { Tweener.removeTweens(this._notificationBin); - let tweenParams = { opacity: 255, - time: ANIMATION_TIME, - transition: 'easeOutQuad', - onComplete: this._showNotificationCompleted, - onCompleteScope: this }; + let tweenParams = { + opacity: 255, + time: ANIMATION_TIME, + transition: 'easeOutQuad', + onComplete: this._showNotificationCompleted, + onCompleteScope: this + }; this._tween(this._notificationBin, '_notificationState', State.SHOWN, tweenParams); - }, + }, - _showNotificationCompleted: function() { + _showNotificationCompleted: function () { this._updateNotificationTimeout(0); this.notificationDuration = this.settings.get_int("notification-duration"); @@ -1034,7 +1069,7 @@ MessageTray.prototype = { } }, - _updateNotificationTimeout: function(timeout) { + _updateNotificationTimeout: function (timeout) { if (this._notificationTimeoutId > 0) { Mainloop.source_remove(this._notificationTimeoutId); this._notificationTimeoutId = 0; @@ -1042,10 +1077,10 @@ MessageTray.prototype = { if (timeout > 0) this._notificationTimeoutId = Mainloop.timeout_add(timeout, - Lang.bind(this, this._notificationTimeout)); + Lang.bind(this, this._notificationTimeout)); }, - _notificationTimeout: function() { + _notificationTimeout: function () { let [x, y, mods] = global.get_pointer(); let distance = Math.abs(this._notificationBin.y - y); if (distance < this._lastSeenMouseDistance - 50 || this._notification && this._notification.actor.hover) { @@ -1063,7 +1098,7 @@ MessageTray.prototype = { return false; }, - _hideNotification: function() { + _hideNotification: function () { let y = Main.layoutManager.primaryMonitor.y; if (this.bottomPosition) { @@ -1083,7 +1118,7 @@ MessageTray.prototype = { }); }, - _hideNotificationCompleted: function() { + _hideNotificationCompleted: function () { this._notificationBin.hide(); this._notificationBin.child = null; let notification = this._notification; @@ -1106,21 +1141,23 @@ function SystemNotificationSource() { } SystemNotificationSource.prototype = { - __proto__: Source.prototype, + __proto__: Source.prototype, - _init: function() { + _init: function () { Source.prototype._init.call(this, _("System Information")); this._setSummaryIcon(this.createNotificationIcon()); }, - createNotificationIcon: function() { - return new St.Icon({ icon_name: 'dialog-information', - icon_type: St.IconType.SYMBOLIC, - icon_size: this.ICON_SIZE }); + createNotificationIcon: function () { + return new St.Icon({ + icon_name: 'dialog-information', + icon_type: St.IconType.SYMBOLIC, + icon_size: this.ICON_SIZE + }); }, - open: function() { + open: function () { this.destroy(); } };