ags icon indicating copy to clipboard operation
ags copied to clipboard

Add method to modify notification ID

Open snod4 opened this issue 1 year ago • 2 comments

Hi, I have a scenario where a program is sending out notifications with the same ID each time.

It seems like the hooks depend on ID. When I try to hook into a notification (2) after a hook has been established for a prior notification (1) with the same ID, the hook does not take effect for (2). It would be nice to have a method to change the ID. I would just modify the ID manually, but I don't know all of where it's used.

I'm using a variant of your dotfile notification popup code in case I'm missing something obvious there:

const NotificationAnimated = (notification) => {
  const inner = Widget.Revealer({
    transition: "slide_left",
    transition_duration: 200,
    child: NotificationTest(notification),
  });
  const outer = Widget.Revealer({
    transition: "slide_left",
    transition_duration: 200,
    child: inner,
  });
  let box = Widget.Box({
    hpack: "end",
    child: outer,
  });

  //Setup initial animation
  Utils.idle(() => {
    outer.revealChild = true;
    Utils.timeout(200, () => {
      inner.revealChild = true;
    });
  });
  box = Object.assign(box, {
    dismiss() {
      Utils.timeout(200, () => {
        inner.revealChild = false;
        Utils.timeout(200, () => {
          outer.revealChild = false;
          box.destroy();
        });
      });
    },
  });

  const remove = () => {
    //Don't dismiss if popup is true
    print("Got here");
    print(notification.id);
    if (notification.popup) {
      return;
    }
    print("Dismissing");
    box.dismiss();
  };
  box
    .hook(notification, remove, "dismissed")
    .hook(notification, remove, "closed");

  return box;
};

snod4 avatar Mar 11 '24 14:03 snod4

It could also be the popupTimeout functionality. When I manually click on the notification, it will dismiss, but it will not do it automatically.

snod4 avatar Mar 11 '24 14:03 snod4

I'm able to sort of workaround it with this:

//Workaround for notifications with same ID?
  Utils.timeout(Notifications.popupTimeout + 1000, () => {
    notification.dismiss();
  });

This allows the earlier notifications to dismiss, but it doesn't fix everything. The popup timeout still uses sends the 'dismiss()' event to the first notification with the ID. That causes the most recent notification to get dismissed before it's time.

snod4 avatar Mar 11 '24 15:03 snod4