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: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3156>
This commit is contained in:
Julian Sparber 2024-01-30 18:04:36 +01:00 committed by Marge Bot
parent daa8ea5ab2
commit 3faf1caead

View File

@ -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( export const SystemNotificationSource = GObject.registerClass(
class SystemNotificationSource extends Source { class SystemNotificationSource extends Source {
constructor() { constructor() {