Removed duplicate code for removing temp notification

This commit is contained in:
Erik Reider
2021-09-18 00:41:27 +02:00
parent cf0e1b347e
commit e205284806

View File

@@ -64,19 +64,15 @@ namespace SwayNotificatonCenter {
} }
} }
private void removeWidget (Gtk.Widget widget) { private void remove_noti (Notification noti) {
uint len = box.get_children ().length () - 1; if (box.get_children ().index (noti) >= 0) {
box.remove (widget); box.remove (noti);
if (len <= 0) this.hide (); }
if (box.get_children ().length () == 0) this.hide ();
} }
public void add_notification (NotifyParams param, NotiDaemon notiDaemon) { public void add_notification (NotifyParams param, NotiDaemon notiDaemon) {
var noti = new Notification.timed (param, notiDaemon, (v_noti) => { var noti = new Notification.timed (param, notiDaemon, remove_noti);
if (box.get_children ().index (v_noti) >= 0) {
box.remove (v_noti);
}
if (box.get_children ().length () == 0) this.hide ();
});
if (list_reverse) { if (list_reverse) {
box.pack_start (noti); box.pack_start (noti);
@@ -92,7 +88,7 @@ namespace SwayNotificatonCenter {
foreach (var w in box.get_children ()) { foreach (var w in box.get_children ()) {
var noti = (Notification) w; var noti = (Notification) w;
if (noti != null && noti.param.applied_id == id) { if (noti != null && noti.param.applied_id == id) {
removeWidget (w); remove_noti (noti);
break; break;
} }
} }