Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to modify notification ID #347

Open
snod4 opened this issue Mar 11, 2024 · 2 comments
Open

Add method to modify notification ID #347

snod4 opened this issue Mar 11, 2024 · 2 comments

Comments

@snod4
Copy link

snod4 commented Mar 11, 2024

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
Copy link
Author

snod4 commented Mar 11, 2024

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
Copy link
Author

snod4 commented Mar 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant