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:
parent
c63d67c9af
commit
932ccac1c2
@ -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');
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user