From 3faf1caeadc73b41ec1c04670f9e07da66e43e8c Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Tue, 30 Jan 2024 18:04:36 +0100 Subject: [PATCH] messageTray: Introduce singleton Source for system notifications This `Source` object should be used by all notifications created by GNOME Shell and eventually can also be used by extensions. Part-of: --- js/ui/messageTray.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 479044a3a..a069f16d4 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -1326,6 +1326,29 @@ export const MessageTray = GObject.registerClass({ } }); +let systemNotificationSource = null; + +/** + * The {Source} that should be used to send system notifications. + * + * @returns {Source} + */ +export function getSystemSource() { + if (!systemNotificationSource) { + systemNotificationSource = new Source({ + title: _('System'), + iconName: 'emblem-system-symbolic', + }); + + systemNotificationSource.connect('destroy', () => { + systemNotificationSource = null; + }); + Main.messageTray.add(systemNotificationSource); + } + + return systemNotificationSource; +} + export const SystemNotificationSource = GObject.registerClass( class SystemNotificationSource extends Source { constructor() {