Skip to content

Commit 6d2f3cc

Browse files
committed
notifications applet: Disconnect signals on applet close and cleanup code a bit
1 parent 63d3679 commit 6d2f3cc

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const Applet = imports.ui.applet;
2-
const Lang = imports.lang;
32
const Main = imports.ui.main;
43
const Gtk = imports.gi.Gtk;
54
const Gio = imports.gi.Gio;
@@ -11,6 +10,7 @@ const NotificationDestroyedReason = imports.ui.messageTray.NotificationDestroyed
1110
const Settings = imports.ui.settings;
1211
const Gettext = imports.gettext.domain("cinnamon-applets");
1312
const Util = imports.misc.util;
13+
const SignalManager = imports.misc.signalManager;
1414

1515
const PANEL_EDIT_MODE_KEY = "panel-edit-mode";
1616

@@ -39,9 +39,10 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
3939
this.notifications = []; // The list of notifications, in order from oldest to newest.
4040

4141
// Events
42-
Main.messageTray.connect('notify-applet-update', Lang.bind(this, this._notification_added));
43-
global.settings.connect('changed::' + PANEL_EDIT_MODE_KEY, Lang.bind(this, this._on_panel_edit_mode_changed));
44-
this.menu.connect('menu-animated-closed', this._onMenuClosed.bind(this));
42+
this.signals = new SignalManager.SignalManager(null);
43+
this.signals.connect(Main.messageTray, 'notify-applet-update', this._notification_added.bind(this));
44+
this.signals.connect(global.settings, 'changed::' + PANEL_EDIT_MODE_KEY, this._on_panel_edit_mode_changed.bind(this));
45+
this.signals.connect(this.menu, 'menu-animated-closed', this._onMenuClosed.bind(this));
4546

4647
// States
4748
this._blinking = false;
@@ -51,13 +52,15 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
5152
}
5253

5354
_setKeybinding() {
54-
Main.keybindingManager.addHotKey("notification-open-" + this.instance_id, this.keyOpen, Lang.bind(this, this._openMenu));
55-
Main.keybindingManager.addHotKey("notification-clear-" + this.instance_id, this.keyClear, Lang.bind(this, this._clear_all));
55+
Main.keybindingManager.addHotKey("notification-open-" + this.instance_id, this.keyOpen, this._openMenu.bind(this));
56+
Main.keybindingManager.addHotKey("notification-clear-" + this.instance_id, this.keyClear, this._clear_all.bind(this));
5657
}
5758

5859
on_applet_removed_from_panel () {
5960
Main.keybindingManager.removeHotKey("notification-open-" + this.instance_id);
6061
Main.keybindingManager.removeHotKey("notification-clear-" + this.instance_id);
62+
63+
this.destroy();
6164
}
6265

6366
_openMenu() {
@@ -82,7 +85,6 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
8285
// Setup the notification container.
8386
this._maincontainer = new St.BoxLayout({name: 'traycontainer', vertical: true});
8487
this._notificationbin = new St.BoxLayout({vertical:true});
85-
this.button_label_box = new St.BoxLayout();
8688

8789
// Setup the tray icon.
8890
this.menu_label = new PopupMenu.PopupMenuItem(stringify(this.notifications.length));
@@ -93,7 +95,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
9395
this.clear_separator = new PopupMenu.PopupSeparatorMenuItem();
9496

9597
this.clear_action = new PopupMenu.PopupMenuItem(_("Clear notifications"));
96-
this.clear_action.connect('activate', Lang.bind(this, this._clear_all));
98+
this.clear_action.connect('activate', this._clear_all.bind(this));
9799
this.clear_action.actor.hide();
98100

99101
this.menu.addMenuItem(this.clear_action);
@@ -108,12 +110,8 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
108110
this.scrollview.set_clip_to_allocation(true);
109111

110112
let vscroll = this.scrollview.get_vscroll_bar();
111-
vscroll.connect('scroll-start', Lang.bind(this, function() {
112-
this.menu.passEvents = true;
113-
}));
114-
vscroll.connect('scroll-stop', Lang.bind(this, function() {
115-
this.menu.passEvents = false;
116-
}));
113+
vscroll.connect('scroll-start', () => this.menu.passEvents = true);
114+
vscroll.connect('scroll-stop', () => this.menu.passEvents = false);
117115

118116
// Alternative tray icons.
119117
this._crit_icon = new St.Icon({icon_name: 'critical-notif', icon_type: St.IconType.SYMBOLIC, reactive: true, track_hover: true, style_class: 'system-status-icon' });
@@ -125,23 +123,22 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
125123
}
126124

127125
_arrangeDisplay() {
128-
// Remove menu actors so we can put tham back in a different order according
129-
// to orientation
126+
// Remove menu actors so we can put them back in a different order according to orientation.
130127
this.menu.box.remove_all_children();
131128

132129
if (this._orientation == St.Side.BOTTOM) {
133-
this.menu.box.add(this.menu_label.actor);
130+
this.menu.addActor(this.menu_label.actor);
134131
this.menu.addActor(this._maincontainer);
135-
this.menu.box.add(this.clear_separator.actor);
136-
this.menu.box.add(this.clear_action.actor);
132+
this.menu.addActor(this.clear_separator.actor);
133+
this.menu.addActor(this.clear_action.actor);
137134
} else {
138-
this.menu.box.add(this.clear_action.actor);
139-
this.menu.box.add(this.clear_separator.actor);
140-
this.menu.box.add(this.menu_label.actor);
135+
this.menu.addActor(this.clear_action.actor);
136+
this.menu.addActor(this.clear_separator.actor);
137+
this.menu.addActor(this.menu_label.actor);
141138
this.menu.addActor(this._maincontainer);
142139
}
143140

144-
this.menu.box.add(this.settingsMenuItem.actor);
141+
this.menu.addActor(this.settingsMenuItem.actor);
145142
}
146143

147144
_notification_added (mtray, notification) { // Notification event handler.
@@ -183,7 +180,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
183180

184181
update_list () {
185182
try {
186-
let count = this.notifications.length;
183+
const count = this.notifications.length;
187184
if (count > 0) { // There are notifications.
188185
this.actor.show();
189186
this.clear_action.actor.show();
@@ -302,7 +299,14 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
302299
this._applet_icon_box.child = this._alt_crit_icon;
303300
}
304301
this._blink_toggle = !this._blink_toggle;
305-
Mainloop.timeout_add_seconds(1, Lang.bind(this, this.critical_blink));
302+
Mainloop.timeout_add_seconds(1, this.critical_blink.bind(this));
303+
}
304+
305+
destroy() {
306+
this.signals.disconnectAllSignals();
307+
this._crit_icon.destroy();
308+
this._alt_crit_icon.destroy();
309+
this.menu.destroy();
306310
}
307311
}
308312

0 commit comments

Comments
 (0)