[gnome-shell] status/network: Simplify notification code
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] status/network: Simplify notification code
- Date: Sun, 7 Aug 2022 22:08:37 +0000 (UTC)
commit c33b5de174f0464ef0e2062c17cabf4c1a3a57c0
Author: Florian Müllner <fmuellner gnome org>
Date: Mon Aug 1 01:30:12 2022 +0200
status/network: Simplify notification code
There is only one case where we show a notification: When activating
a connection failed.
There is therefore no reason for a generic wrapper around the
notification API. Likewise, tracking the source is a bit pointless,
given that the notification is transient. In fact, as we destroy
an existing notification *before* checking for the source, any
previous source will be gone by that point.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2406>
js/ui/status/network.js | 44 ++++++++++++++------------------------------
1 file changed, 14 insertions(+), 30 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index c31797a4ad..db604be4d2 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -1814,17 +1814,6 @@ class Indicator extends PanelMenu.SystemIndicator {
this.menu.setSensitive(sensitive);
}
- _ensureSource() {
- if (!this._source) {
- this._source = new MessageTray.Source(_("Network Manager"),
- 'network-transmit-receive');
- this._source.policy = new MessageTray.NotificationApplicationPolicy('gnome-network-panel');
-
- this._source.connect('destroy', () => (this._source = null));
- Main.messageTray.add(this._source);
- }
- }
-
_readDevices() {
let devices = this._client.get_devices() || [];
for (let i = 0; i < devices.length; ++i) {
@@ -1837,29 +1826,24 @@ class Indicator extends PanelMenu.SystemIndicator {
this._syncDeviceNames();
}
- _notify(iconName, title, text, urgency) {
- if (this._notification)
- this._notification.destroy();
+ _onActivationFailed() {
+ this._notification?.destroy();
- this._ensureSource();
+ const source = new MessageTray.Source(
+ _('Network Manager'), 'network-error-symbolic');
+ source.policy =
+ new MessageTray.NotificationApplicationPolicy('gnome-network-panel');
- let gicon = new Gio.ThemedIcon({ name: iconName });
- this._notification = new MessageTray.Notification(this._source, title, text, { gicon });
- this._notification.setUrgency(urgency);
+ this._notification = new MessageTray.Notification(source,
+ _('Connection failed'),
+ _('Activation of network connection failed'));
+ this._notification.setUrgency(MessageTray.Urgency.HIGH);
this._notification.setTransient(true);
- this._notification.connect('destroy', () => {
- this._notification = null;
- });
- this._source.showNotification(this._notification);
- }
+ this._notification.connect('destroy',
+ () => (this._notification = null));
- _onActivationFailed() {
- // XXX: nm-applet has no special text depending on reason
- // but I'm not sure of this generic message
- this._notify('network-error-symbolic',
- _("Connection failed"),
- _("Activation of network connection failed"),
- MessageTray.Urgency.HIGH);
+ Main.messageTray.add(source);
+ source.showNotification(this._notification);
}
_syncDeviceNames() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]