messageTray: Allow settings gobject properties of Source on creation

This also makes the `icon` property of `Source` writable so that it can
be set during creation instead of overriding the getter of the icon
property.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3103>
This commit is contained in:
Julian Sparber 2024-01-25 21:52:34 +01:00 committed by Marge Bot
parent c63d67c9af
commit 932ccac1c2
11 changed files with 69 additions and 69 deletions

View File

@ -258,8 +258,11 @@ class AutorunDispatcher {
const AutorunSource = GObject.registerClass( const AutorunSource = GObject.registerClass(
class AutorunSource extends MessageTray.Source { class AutorunSource extends MessageTray.Source {
_init(manager, mount, apps) { constructor(manager, mount, apps) {
super._init(mount.get_name()); super({
title: mount.get_name(),
icon: mount.get_icon(),
});
this._manager = manager; this._manager = manager;
this.mount = mount; this.mount = mount;
@ -272,10 +275,6 @@ class AutorunSource extends MessageTray.Source {
this.showNotification(this._notification); this.showNotification(this._notification);
} }
get icon() {
return this.mount.get_icon();
}
_createPolicy() { _createPolicy() {
return new MessageTray.NotificationApplicationPolicy('org.gnome.Nautilus'); return new MessageTray.NotificationApplicationPolicy('org.gnome.Nautilus');
} }

View File

@ -740,7 +740,10 @@ class NetworkAgent {
} }
_showNotification(requestId, connection, settingName, hints, flags) { _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'); source.policy = new MessageTray.NotificationApplicationPolicy('gnome-network-panel');
let title, body; let title, body;

View File

@ -312,7 +312,7 @@ class ChatSource extends MessageTray.Source {
this._contact = contact; this._contact = contact;
this._client = client; this._client = client;
super._init(contact.get_alias()); super._init();
this._pendingMessages = []; this._pendingMessages = [];
@ -333,6 +333,8 @@ class ChatSource extends MessageTray.Source {
'notify::alias', this._updateAlias.bind(this), 'notify::alias', this._updateAlias.bind(this),
'notify::avatar-file', this._updateAvatarIcon.bind(this), this); 'notify::avatar-file', this._updateAvatarIcon.bind(this), this);
this._updateAlias();
this._updateAvatarIcon();
// Add ourselves as a source. // Add ourselves as a source.
Main.messageTray.add(this); Main.messageTray.add(this);
@ -378,22 +380,23 @@ class ChatSource extends MessageTray.Source {
if (oldAlias === newAlias) if (oldAlias === newAlias)
return; return;
this.setTitle(newAlias); this.title = newAlias;
if (this._notification) if (this._notification)
this._notification.appendAliasChange(oldAlias, newAlias); 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() { _updateAvatarIcon() {
this.notify('icon'); let file = this._contact.get_avatar_file();
if (this._notification) { 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.update(
this._notification.title, this._notification.title,
this._notification.bannerBodyText, this._notification.bannerBodyText,

View File

@ -830,11 +830,10 @@ class ExtensionUpdateSource extends MessageTray.Source {
if (!this._app) if (!this._app)
this._app = appSys.lookup_app('com.mattjakeman.ExtensionManager.desktop'); this._app = appSys.lookup_app('com.mattjakeman.ExtensionManager.desktop');
super._init(this._app.get_name()); super._init({
} title: this._app.get_name(),
icon: this._app.get_icon(),
get icon() { });
return this._app.app_info.get_icon();
} }
_createPolicy() { _createPolicy() {

View File

@ -609,10 +609,8 @@ export const Source = GObject.registerClass({
'notification-show': {param_types: [Notification.$gtype]}, 'notification-show': {param_types: [Notification.$gtype]},
}, },
}, class Source extends GObject.Object { }, class Source extends GObject.Object {
_init(title, iconName) { constructor(params) {
super._init({title}); super(params);
this.icon = new Gio.ThemedIcon({name: iconName});
this.notifications = []; this.notifications = [];
@ -655,14 +653,6 @@ export const Source = GObject.registerClass({
: PrivacyScope.USER; : PrivacyScope.USER;
} }
setTitle(newTitle) {
if (this.title === newTitle)
return;
this.title = newTitle;
this.notify('title');
}
createBanner(notification) { createBanner(notification) {
return new NotificationBanner(notification); return new NotificationBanner(notification);
} }
@ -1349,8 +1339,11 @@ export const MessageTray = GObject.registerClass({
export const SystemNotificationSource = GObject.registerClass( export const SystemNotificationSource = GObject.registerClass(
class SystemNotificationSource extends Source { class SystemNotificationSource extends Source {
_init() { constructor() {
super._init(_('System Information'), 'dialog-information-symbolic'); super({
title: _('System Information'),
iconName: 'dialog-information-symbolic',
});
} }
open() { open() {

View File

@ -309,10 +309,13 @@ class FdoNotificationDaemonSource extends MessageTray.Source {
this.pid = pid; this.pid = pid;
this.initialTitle = title; this.initialTitle = title;
this.app = this._getApp(appId); this.app = this._getApp(appId);
this._appIcon = null;
// Use app name as title if available, instead of whatever is provided // Use app name as title if available, instead of whatever is provided
// through libnotify (usually garbage) // through libnotify (usually garbage)
super._init(this.app ? this.app.get_name() : title); super._init({
title: this.app?.get_name() ?? title,
});
if (sender) { if (sender) {
this._nameWatcherId = Gio.DBus.session.watch_name(sender, this._nameWatcherId = Gio.DBus.session.watch_name(sender,
@ -349,6 +352,7 @@ class FdoNotificationDaemonSource extends MessageTray.Source {
this.notify('icon'); this.notify('icon');
} }
let tracker = Shell.WindowTracker.get_default(); let tracker = Shell.WindowTracker.get_default();
if (notification.resident && this.app && tracker.focus_app === this.app) if (notification.resident && this.app && tracker.focus_app === this.app)
this.pushNotification(notification); this.pushNotification(notification);
@ -397,12 +401,7 @@ class FdoNotificationDaemonSource extends MessageTray.Source {
} }
get icon() { get icon() {
if (this.app) return this.app?.get_icon() ?? this._appIcon;
return this.app.get_icon();
else if (this._appIcon)
return this._appIcon;
else
return null;
} }
}); });
@ -519,16 +518,15 @@ class GtkNotificationDaemonAppSource extends MessageTray.Source {
this._app = app; this._app = app;
this._objectPath = objectPath; this._objectPath = objectPath;
super._init(app.get_name()); super._init({
title: app.get_name(),
icon: app.get_icon(),
});
this._notifications = {}; this._notifications = {};
this._notificationPending = false; this._notificationPending = false;
} }
get icon() {
return this._app.get_icon();
}
_createPolicy() { _createPolicy() {
return new MessageTray.NotificationApplicationPolicy(this._appId); return new MessageTray.NotificationApplicationPolicy(this._appId);
} }

View File

@ -2025,11 +2025,11 @@ export const ScreenshotUI = GObject.registerClass({
// Show a notification. // Show a notification.
const file = Gio.file_new_for_path(this._screencastPath); const file = Gio.file_new_for_path(this._screencastPath);
const source = new MessageTray.Source( const source = new MessageTray.Source({
// Translators: notification source name. // Translators: notification source name.
_('Screenshot'), title: _('Screenshot'),
'screencast-recorded-symbolic' iconName: 'screencast-recorded-symbolic',
); });
const notification = new MessageTray.Notification( const notification = new MessageTray.Notification(
source, source,
title, title,
@ -2262,11 +2262,11 @@ function _storeScreenshot(bytes, pixbuf) {
); );
// Show a notification. // Show a notification.
const source = new MessageTray.Source( const source = new MessageTray.Source({
// Translators: notification source name. // Translators: notification source name.
_('Screenshot'), title: _('Screenshot'),
'screenshot-recorded-symbolic' iconName: 'screenshot-recorded-symbolic',
); });
const notification = new MessageTray.Notification( const notification = new MessageTray.Notification(
source, source,
// Translators: notification title. // Translators: notification title.

View File

@ -198,8 +198,10 @@ export class ShellMountOperation {
const ShellUnmountNotifier = GObject.registerClass( const ShellUnmountNotifier = GObject.registerClass(
class ShellUnmountNotifier extends MessageTray.Source { class ShellUnmountNotifier extends MessageTray.Source {
_init() { constructor() {
super._init('', 'media-removable'); super({
iconName: 'media-removable',
});
this._notification = null; this._notification = null;
Main.messageTray.add(this); Main.messageTray.add(this);

View File

@ -2036,8 +2036,10 @@ class Indicator extends SystemIndicator {
_onActivationFailed() { _onActivationFailed() {
this._notification?.destroy(); this._notification?.destroy();
const source = new MessageTray.Source( const source = new MessageTray.Source({
_('Network Manager'), 'network-error-symbolic'); title: _('Network Manager'),
iconName: 'network-error-symbolic',
});
source.policy = source.policy =
new MessageTray.NotificationApplicationPolicy('gnome-network-panel'); new MessageTray.NotificationApplicationPolicy('gnome-network-panel');

View File

@ -256,8 +256,10 @@ class Indicator extends SystemIndicator {
_ensureSource() { _ensureSource() {
if (!this._source) { if (!this._source) {
this._source = new MessageTray.Source(_('Thunderbolt'), this._source = new MessageTray.Source({
'thunderbolt-symbolic'); title: _('Thunderbolt'),
iconName: 'thunderbolt-symbolic',
});
this._source.connect('destroy', () => (this._source = null)); this._source.connect('destroy', () => (this._source = null));
Main.messageTray.add(this._source); Main.messageTray.add(this._source);

View File

@ -60,7 +60,10 @@ class WindowAttentionSource extends MessageTray.Source {
this._window = window; this._window = window;
this._app = app; this._app = app;
super._init(app.get_name()); super._init({
title: this._app.get_name(),
icon: this._app.get_icon(),
});
this._window.connectObject( this._window.connectObject(
'notify::demands-attention', this._sync.bind(this), '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) { destroy(params) {
this._window.disconnectObject(this); this._window.disconnectObject(this);