PNotify infinite delay

I once had this idea to Show a pop-up message from outside OP. I've started on this a year ago and now finally found some time to continue. I have to say it's working nicely, but I seem unable to disable the delay on the PNotify popup.
According to the PNotify docs, the delay should be set to Infinity to disable it. This is a snippet from my JS:

if (data.msg_delay == 0) {
    msg_delay = Infinity;
}
else {
    msg_delay = data.msg_delay;
}
console.log(msg_delay);

new PNotify({
    title: data.msg_title,
    text: data.msg_text,
    type: data.msg_level,
    delay: msg_delay,

Any non-zero value will show the pop-up for that amount of milliseconds. However, when set to Infinity, it shows and directly disappears. The console.log will however show that the msg_delay variable is set to Infinity.
Anyone who has an idea on this?

Apparently, no delay over 10 seconds is being accepted.
Should anybody be curious, you can install the plugin from my repo.

Just set the pnotify hide attribute to false instead of trying to use an infinite delay.

Here's what I would do.

        self.onDataUpdaterPluginMessage = function(plugin, data) {
            if (plugin == "notifications" && data.type == "popup") {
                if (data.msg_id === "none") {
                    var buttons = [
                        {
                            text: "Mark read",
                            click: function(notice) {
                                notice.remove();
                            }
                        },
                        {
                            text: "Should not be seen",
                            addClass: "remove_button"
                        },
                    ]
                }
                else {
                    var buttons = [
                        {
                            text: "Later",
                            click: function(notice) {
                                notice.remove();
                            }
                        },
                        {
                            text: "Mark read",
                            click: function(notice) {
                                self.removeNotification(data.msg_id);
                                notice.remove();
                            }
                        },
                    ]
                }
                var pnotify_options = {
                    title: data.msg_title,
                    text: data.msg_text,
                    type: data.msg_level,
                    confirm: {
                        confirm: true,
                        buttons: buttons,
                    }
                if (data.msg_delay == 0) {
                    pnotify_options["hide"] = false
                }
                else {
                    pnotify_options["delay"] = data.msg_delay
                }
                new PNotify(pnotify_options,
                    before_open: function(notice) {
                        // Remove the button we don't want
                        notice.get().find(".remove_button").remove();
                    },
                });
            }
        };
1 Like

If you were looking at Pnotify docs, they are most likely completely wrong - OctoPrint's version is 2.0.1, which is from 2014. There are a lot of breaking changes that make upgrading rather difficult. I think I tried at some point.

If you want a reference for the options, you can look back at the Pnotify repository at that tag, GitHub - sciactive/pnotify at bb727c99f50f8c9819ad5e7446729a957cd1e54c

1 Like