From ff765849379daa09aa42ee3c29dc94e48484465d Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Fri, 26 Jan 2024 11:05:46 +0100 Subject: [PATCH] notifications: Introduce MessageList.Source object This object contains only the `title` and `icon` of a `MessageTray.Source` which allows using it for sources that aren't notification sources like mpris. The old `MessageTray.Source` isn't renamed to something less generic to not break API. Once we have a good reason we should rename it to something more specific. Part-of: --- js/ui/messageList.js | 28 ++++++++++++++++++++++++++++ js/ui/messageTray.js | 26 ++------------------------ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/js/ui/messageList.js b/js/ui/messageList.js index d4967ebf6..2ecea4965 100644 --- a/js/ui/messageList.js +++ b/js/ui/messageList.js @@ -306,6 +306,34 @@ const LabelExpanderLayout = GObject.registerClass({ } }); +export const Source = GObject.registerClass({ + Properties: { + 'title': GObject.ParamSpec.string( + 'title', 'title', 'title', + GObject.ParamFlags.READWRITE, + null), + 'icon': GObject.ParamSpec.object( + 'icon', 'icon', 'icon', + GObject.ParamFlags.READWRITE, + Gio.Icon), + 'icon-name': GObject.ParamSpec.string( + 'icon-name', 'icon-name', 'icon-name', + GObject.ParamFlags.READWRITE, + null), + }, +}, class Source extends GObject.Object { + get iconName() { + if (this.gicon instanceof Gio.ThemedIcon) + return this.gicon.iconName; + else + return null; + } + + set iconName(iconName) { + this.icon = new Gio.ThemedIcon({name: iconName}); + } +}); + const TimeLabel = GObject.registerClass( class TimeLabel extends St.Label { _init() { diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index bd8be9b29..7427b4a51 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -12,6 +12,7 @@ import * as Calendar from './calendar.js'; import * as GnomeSession from '../misc/gnomeSession.js'; import * as Layout from './layout.js'; import * as Main from './main.js'; +import * as MessageList from './messageList.js'; import * as Params from '../misc/params.js'; import * as SignalTracker from '../misc/signalTracker.js'; @@ -590,25 +591,13 @@ export const Source = GObject.registerClass({ 'policy', 'policy', 'policy', GObject.ParamFlags.READWRITE, NotificationPolicy.$gtype), - 'title': GObject.ParamSpec.string( - 'title', 'title', 'title', - GObject.ParamFlags.READWRITE, - null), - 'icon': GObject.ParamSpec.object( - 'icon', 'icon', 'icon', - GObject.ParamFlags.READWRITE, - Gio.Icon), - 'icon-name': GObject.ParamSpec.string( - 'icon-name', 'icon-name', 'icon-name', - GObject.ParamFlags.READWRITE, - null), }, Signals: { 'destroy': {param_types: [GObject.TYPE_UINT]}, 'notification-added': {param_types: [Notification.$gtype]}, 'notification-show': {param_types: [Notification.$gtype]}, }, -}, class Source extends GObject.Object { +}, class Source extends MessageList.Source { constructor(params) { super(params); @@ -657,17 +646,6 @@ export const Source = GObject.registerClass({ return new NotificationBanner(notification); } - get iconName() { - if (this.gicon instanceof Gio.ThemedIcon) - return this.gicon.iconName; - else - return null; - } - - set iconName(iconName) { - this.icon = new Gio.ThemedIcon({name: iconName}); - } - _onNotificationDestroy(notification) { let index = this.notifications.indexOf(notification); if (index < 0)