diff --git a/js/ui/components/autorunManager.js b/js/ui/components/autorunManager.js index 9570b1219..1ca58510f 100644 --- a/js/ui/components/autorunManager.js +++ b/js/ui/components/autorunManager.js @@ -258,8 +258,11 @@ class AutorunDispatcher { const AutorunSource = GObject.registerClass( class AutorunSource extends MessageTray.Source { - _init(manager, mount, apps) { - super._init(mount.get_name()); + constructor(manager, mount, apps) { + super({ + title: mount.get_name(), + icon: mount.get_icon(), + }); this._manager = manager; this.mount = mount; @@ -272,10 +275,6 @@ class AutorunSource extends MessageTray.Source { this.showNotification(this._notification); } - get icon() { - return this.mount.get_icon(); - } - _createPolicy() { return new MessageTray.NotificationApplicationPolicy('org.gnome.Nautilus'); } diff --git a/js/ui/components/networkAgent.js b/js/ui/components/networkAgent.js index 3d187a878..2a31b3037 100644 --- a/js/ui/components/networkAgent.js +++ b/js/ui/components/networkAgent.js @@ -740,7 +740,10 @@ class NetworkAgent { } _showNotification(requestId, connection, settingName, hints, flags) { - let source = new MessageTray.Source(_('Network Manager'), 'network-transmit-receive'); + const source = new MessageTray.Source({ + title: _('Network Manager'), + iconName: 'network-transmit-receive', + }); source.policy = new MessageTray.NotificationApplicationPolicy('gnome-network-panel'); let title, body; diff --git a/js/ui/components/telepathyClient.js b/js/ui/components/telepathyClient.js index 5a5aec359..04d6f3af7 100644 --- a/js/ui/components/telepathyClient.js +++ b/js/ui/components/telepathyClient.js @@ -312,7 +312,7 @@ class ChatSource extends MessageTray.Source { this._contact = contact; this._client = client; - super._init(contact.get_alias()); + super._init(); this._pendingMessages = []; @@ -333,6 +333,8 @@ class ChatSource extends MessageTray.Source { 'notify::alias', this._updateAlias.bind(this), 'notify::avatar-file', this._updateAvatarIcon.bind(this), this); + this._updateAlias(); + this._updateAvatarIcon(); // Add ourselves as a source. Main.messageTray.add(this); @@ -378,22 +380,23 @@ class ChatSource extends MessageTray.Source { if (oldAlias === newAlias) return; - this.setTitle(newAlias); + this.title = newAlias; if (this._notification) this._notification.appendAliasChange(oldAlias, newAlias); } - get icon() { - let file = this._contact.get_avatar_file(); - if (file) - return new Gio.FileIcon({file}); - else - return new Gio.ThemedIcon({name: 'avatar-default'}); - } - _updateAvatarIcon() { - this.notify('icon'); - if (this._notification) { + let file = this._contact.get_avatar_file(); + if (file) { + if (this.icon instanceof Gio.FileIcon) + this.icon.file = file; + else + this.icon = new Gio.FileIcon({file}); + } else if (!(this.icon instanceof Gio.ThemedIcon)) { + this.iconName = 'avatar-default'; + } + + if (this._notification && this.icon !== this._notification.gicon) { this._notification.update( this._notification.title, this._notification.bannerBodyText, diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index 356c43b2d..b3e43b139 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -830,11 +830,10 @@ class ExtensionUpdateSource extends MessageTray.Source { if (!this._app) this._app = appSys.lookup_app('com.mattjakeman.ExtensionManager.desktop'); - super._init(this._app.get_name()); - } - - get icon() { - return this._app.app_info.get_icon(); + super._init({ + title: this._app.get_name(), + icon: this._app.get_icon(), + }); } _createPolicy() { diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 7acccc9c4..bd8be9b29 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -609,10 +609,8 @@ export const Source = GObject.registerClass({ 'notification-show': {param_types: [Notification.$gtype]}, }, }, class Source extends GObject.Object { - _init(title, iconName) { - super._init({title}); - - this.icon = new Gio.ThemedIcon({name: iconName}); + constructor(params) { + super(params); this.notifications = []; @@ -655,14 +653,6 @@ export const Source = GObject.registerClass({ : PrivacyScope.USER; } - setTitle(newTitle) { - if (this.title === newTitle) - return; - - this.title = newTitle; - this.notify('title'); - } - createBanner(notification) { return new NotificationBanner(notification); } @@ -1349,8 +1339,11 @@ export const MessageTray = GObject.registerClass({ export const SystemNotificationSource = GObject.registerClass( class SystemNotificationSource extends Source { - _init() { - super._init(_('System Information'), 'dialog-information-symbolic'); + constructor() { + super({ + title: _('System Information'), + iconName: 'dialog-information-symbolic', + }); } open() { diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js index 23d44458c..cec670dd0 100644 --- a/js/ui/notificationDaemon.js +++ b/js/ui/notificationDaemon.js @@ -309,10 +309,13 @@ class FdoNotificationDaemonSource extends MessageTray.Source { this.pid = pid; this.initialTitle = title; this.app = this._getApp(appId); + this._appIcon = null; // Use app name as title if available, instead of whatever is provided // through libnotify (usually garbage) - super._init(this.app ? this.app.get_name() : title); + super._init({ + title: this.app?.get_name() ?? title, + }); if (sender) { this._nameWatcherId = Gio.DBus.session.watch_name(sender, @@ -349,6 +352,7 @@ class FdoNotificationDaemonSource extends MessageTray.Source { this.notify('icon'); } + let tracker = Shell.WindowTracker.get_default(); if (notification.resident && this.app && tracker.focus_app === this.app) this.pushNotification(notification); @@ -397,12 +401,7 @@ class FdoNotificationDaemonSource extends MessageTray.Source { } get icon() { - if (this.app) - return this.app.get_icon(); - else if (this._appIcon) - return this._appIcon; - else - return null; + return this.app?.get_icon() ?? this._appIcon; } }); @@ -519,16 +518,15 @@ class GtkNotificationDaemonAppSource extends MessageTray.Source { this._app = app; this._objectPath = objectPath; - super._init(app.get_name()); + super._init({ + title: app.get_name(), + icon: app.get_icon(), + }); this._notifications = {}; this._notificationPending = false; } - get icon() { - return this._app.get_icon(); - } - _createPolicy() { return new MessageTray.NotificationApplicationPolicy(this._appId); } diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js index 464e95672..e5b50604d 100644 --- a/js/ui/screenshot.js +++ b/js/ui/screenshot.js @@ -2025,11 +2025,11 @@ export const ScreenshotUI = GObject.registerClass({ // Show a notification. const file = Gio.file_new_for_path(this._screencastPath); - const source = new MessageTray.Source( + const source = new MessageTray.Source({ // Translators: notification source name. - _('Screenshot'), - 'screencast-recorded-symbolic' - ); + title: _('Screenshot'), + iconName: 'screencast-recorded-symbolic', + }); const notification = new MessageTray.Notification( source, title, @@ -2262,11 +2262,11 @@ function _storeScreenshot(bytes, pixbuf) { ); // Show a notification. - const source = new MessageTray.Source( + const source = new MessageTray.Source({ // Translators: notification source name. - _('Screenshot'), - 'screenshot-recorded-symbolic' - ); + title: _('Screenshot'), + iconName: 'screenshot-recorded-symbolic', + }); const notification = new MessageTray.Notification( source, // Translators: notification title. diff --git a/js/ui/shellMountOperation.js b/js/ui/shellMountOperation.js index caef313af..d2ab86758 100644 --- a/js/ui/shellMountOperation.js +++ b/js/ui/shellMountOperation.js @@ -198,8 +198,10 @@ export class ShellMountOperation { const ShellUnmountNotifier = GObject.registerClass( class ShellUnmountNotifier extends MessageTray.Source { - _init() { - super._init('', 'media-removable'); + constructor() { + super({ + iconName: 'media-removable', + }); this._notification = null; Main.messageTray.add(this); diff --git a/js/ui/status/network.js b/js/ui/status/network.js index d9547eed7..4322c6761 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -2036,8 +2036,10 @@ class Indicator extends SystemIndicator { _onActivationFailed() { this._notification?.destroy(); - const source = new MessageTray.Source( - _('Network Manager'), 'network-error-symbolic'); + const source = new MessageTray.Source({ + title: _('Network Manager'), + iconName: 'network-error-symbolic', + }); source.policy = new MessageTray.NotificationApplicationPolicy('gnome-network-panel'); diff --git a/js/ui/status/thunderbolt.js b/js/ui/status/thunderbolt.js index 0005339d0..51b6e4ba6 100644 --- a/js/ui/status/thunderbolt.js +++ b/js/ui/status/thunderbolt.js @@ -256,8 +256,10 @@ class Indicator extends SystemIndicator { _ensureSource() { if (!this._source) { - this._source = new MessageTray.Source(_('Thunderbolt'), - 'thunderbolt-symbolic'); + this._source = new MessageTray.Source({ + title: _('Thunderbolt'), + iconName: 'thunderbolt-symbolic', + }); this._source.connect('destroy', () => (this._source = null)); Main.messageTray.add(this._source); diff --git a/js/ui/windowAttentionHandler.js b/js/ui/windowAttentionHandler.js index 8ba38685e..dfce5c1b9 100644 --- a/js/ui/windowAttentionHandler.js +++ b/js/ui/windowAttentionHandler.js @@ -60,7 +60,10 @@ class WindowAttentionSource extends MessageTray.Source { this._window = window; this._app = app; - super._init(app.get_name()); + super._init({ + title: this._app.get_name(), + icon: this._app.get_icon(), + }); this._window.connectObject( 'notify::demands-attention', this._sync.bind(this), @@ -84,10 +87,6 @@ class WindowAttentionSource extends MessageTray.Source { } } - get icon() { - return this._app.get_icon(); - } - destroy(params) { this._window.disconnectObject(this);