1
1
const Applet = imports . ui . applet ;
2
- const Lang = imports . lang ;
3
2
const Main = imports . ui . main ;
4
3
const Gtk = imports . gi . Gtk ;
5
4
const Gio = imports . gi . Gio ;
@@ -11,6 +10,7 @@ const NotificationDestroyedReason = imports.ui.messageTray.NotificationDestroyed
11
10
const Settings = imports . ui . settings ;
12
11
const Gettext = imports . gettext . domain ( "cinnamon-applets" ) ;
13
12
const Util = imports . misc . util ;
13
+ const SignalManager = imports . misc . signalManager ;
14
14
15
15
const PANEL_EDIT_MODE_KEY = "panel-edit-mode" ;
16
16
@@ -39,9 +39,10 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
39
39
this . notifications = [ ] ; // The list of notifications, in order from oldest to newest.
40
40
41
41
// 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 ) ) ;
45
46
46
47
// States
47
48
this . _blinking = false ;
@@ -51,13 +52,15 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
51
52
}
52
53
53
54
_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 ) ) ;
56
57
}
57
58
58
59
on_applet_removed_from_panel ( ) {
59
60
Main . keybindingManager . removeHotKey ( "notification-open-" + this . instance_id ) ;
60
61
Main . keybindingManager . removeHotKey ( "notification-clear-" + this . instance_id ) ;
62
+
63
+ this . destroy ( ) ;
61
64
}
62
65
63
66
_openMenu ( ) {
@@ -82,7 +85,6 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
82
85
// Setup the notification container.
83
86
this . _maincontainer = new St . BoxLayout ( { name : 'traycontainer' , vertical : true } ) ;
84
87
this . _notificationbin = new St . BoxLayout ( { vertical :true } ) ;
85
- this . button_label_box = new St . BoxLayout ( ) ;
86
88
87
89
// Setup the tray icon.
88
90
this . menu_label = new PopupMenu . PopupMenuItem ( stringify ( this . notifications . length ) ) ;
@@ -93,7 +95,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
93
95
this . clear_separator = new PopupMenu . PopupSeparatorMenuItem ( ) ;
94
96
95
97
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 ) ) ;
97
99
this . clear_action . actor . hide ( ) ;
98
100
99
101
this . menu . addMenuItem ( this . clear_action ) ;
@@ -108,12 +110,8 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
108
110
this . scrollview . set_clip_to_allocation ( true ) ;
109
111
110
112
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 ) ;
117
115
118
116
// Alternative tray icons.
119
117
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 {
125
123
}
126
124
127
125
_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.
130
127
this . menu . box . remove_all_children ( ) ;
131
128
132
129
if ( this . _orientation == St . Side . BOTTOM ) {
133
- this . menu . box . add ( this . menu_label . actor ) ;
130
+ this . menu . addActor ( this . menu_label . actor ) ;
134
131
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 ) ;
137
134
} 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 ) ;
141
138
this . menu . addActor ( this . _maincontainer ) ;
142
139
}
143
140
144
- this . menu . box . add ( this . settingsMenuItem . actor ) ;
141
+ this . menu . addActor ( this . settingsMenuItem . actor ) ;
145
142
}
146
143
147
144
_notification_added ( mtray , notification ) { // Notification event handler.
@@ -183,7 +180,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
183
180
184
181
update_list ( ) {
185
182
try {
186
- let count = this . notifications . length ;
183
+ const count = this . notifications . length ;
187
184
if ( count > 0 ) { // There are notifications.
188
185
this . actor . show ( ) ;
189
186
this . clear_action . actor . show ( ) ;
@@ -302,7 +299,14 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
302
299
this . _applet_icon_box . child = this . _alt_crit_icon ;
303
300
}
304
301
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 ( ) ;
306
310
}
307
311
}
308
312
0 commit comments