notification: Use the same Source for showing system notifications

This drops all subclasses of `MessageTray.Source` that were used to
display system notifications. Now the `Source` returned from
`MessageTray.getSystemSource()` is used.
Ensure also that properties and methods that where set on the `Source`
are moved to the `Notification` object itself.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3156>
This commit is contained in:
Julian Sparber
2024-02-02 15:42:31 +01:00
committed by Marge Bot
parent 3faf1caead
commit c1ff00c01b
9 changed files with 65 additions and 178 deletions

View File

@ -6,7 +6,6 @@ import GObject from 'gi://GObject';
import St from 'gi://St';
import * as GnomeSession from '../../misc/gnomeSession.js';
import * as Main from '../main.js';
import * as MessageTray from '../messageTray.js';
Gio._promisify(Gio.Mount.prototype, 'guess_content_type');
@ -165,7 +164,7 @@ class AutorunManager {
class AutorunDispatcher {
constructor(manager) {
this._manager = manager;
this._sources = [];
this._notifications = new Map();
this._settings = new Gio.Settings({schema_id: SETTINGS_SCHEMA});
}
@ -185,26 +184,16 @@ class AutorunDispatcher {
return AutorunSetting.ASK;
}
_getSourceForMount(mount) {
let filtered = this._sources.filter(source => source.mount === mount);
// we always make sure not to add two sources for the same
// mount in addMount(), so it's safe to assume filtered.length
// is always either 1 or 0.
if (filtered.length === 1)
return filtered[0];
return null;
}
_addSource(mount, apps) {
// if we already have a source showing for this
// mount, return
if (this._getSourceForMount(mount))
_addNotification(mount, apps) {
// Only show a new notification if there isn't already an existing one
if (this._notifications.has(mount))
return;
// add a new source
this._sources.push(new AutorunSource(this._manager, mount, apps));
const source = MessageTray.getSystemSource();
const notification = new AutorunNotification(source, mount, apps);
notification.connect('destroy', () => this._notifications.delete(mount));
this._notifications.set(mount, notification);
source.showNotification(notification);
}
addMount(mount, apps, contentTypes) {
@ -241,58 +230,29 @@ class AutorunDispatcher {
// we fallback here also in case the settings did not specify 'ask',
// but we failed launching the default app or the default file manager
if (!success)
this._addSource(mount, apps);
this._addNotification(mount, apps);
}
removeMount(mount) {
let source = this._getSourceForMount(mount);
// if we aren't tracking this mount, don't do anything
if (!source)
return;
// destroy the notification source
source.destroy();
this._notifications.get(mount)?.destroy();
}
}
const AutorunSource = GObject.registerClass(
class AutorunSource extends MessageTray.Source {
constructor(manager, mount, apps) {
super({
title: mount.get_name(),
icon: mount.get_icon(),
});
this._manager = manager;
this.mount = mount;
this.apps = apps;
this._notification = new AutorunNotification(this._manager, this);
// add ourselves as a source, and popup the notification
Main.messageTray.add(this);
this.showNotification(this._notification);
}
_createPolicy() {
return new MessageTray.NotificationApplicationPolicy('org.gnome.Nautilus');
}
});
const AutorunNotification = GObject.registerClass(
class AutorunNotification extends MessageTray.Notification {
_init(manager, source) {
super._init(source, source.title);
constructor(source, mount, apps) {
super(source, mount.get_name());
this._manager = manager;
this._mount = source.mount;
this.gicon = mount.get_icon();
this._mount = mount;
this._apps = apps;
}
createBanner() {
let banner = new MessageTray.NotificationBanner(this);
this.source.apps.forEach(app => {
this._apps.forEach(app => {
let actor = this._buttonForApp(app);
if (actor)