function myNotification() {
var notification = browser.notifications.create("online_status",{
"type": "basic",
"iconUrl": browser.extension.getURL("icons/64.png"),
"title": title,
"message": "Click this message to visit the website!"
});
browser.notifications.onClicked.addListener(function() {
browser.tabs.create({"url": "http://www.url.com/" + channelName});
});
}
I shorten it a bit to just show the important things.
Now this notification pop up, and close after ~12 sec or something.
I just want to KEEP the Notification in my Chrome Extension alive forever.
Until a user interaction happens. Like a click to open the website, or a click to close the notification.
So I can trigger the onClosed AND onClicked events.
Right now I have no chance to figure out if someone clicked on the "X Button" right top corner, to close the Notification.
If the Notification stay alive forever, I can use the "onClosed" to see if someone only press the X to close it.
Or onClicked if someone wants to open the website.
This is important because this defines how long the Notification will not popup again.
Every 5 minutes my extension check for live status. When live notification apears.
When someone click the notification they come to the website. And the extension don't check for 9h for live status anymore.
IF someone click the close button (no fun to see it live today) notification willnot show up for 9h aswell.
At the moment, the Notification disapears after 12 seconds...
And the X close button have NO effect.
So people have to CLICK the Notification (onClicked event triggers) and I can set it to "don't show it for 9h anymore".
That means, people who don't want to visit it right now, HAVE to click (open website) and close website again, so that this Notifcation will not show up again.
Because since the Notification hides after ~12 seconds, I made a midrotation.
Normally check for live status every 5 minutes. If Notification apears, but not clicked (means someone wasn't at the PC, on toilette or something) the Notification comes again after 30 minutes.
So it will show up every 30 minutes... UNTIL a user click (open website) and close webseite again (if no fun to watch)...
And that's not cool. So IF the Notification stays alive forever.
I can do the onClosed and onClicked event.
I tested it that way:
function myNotification() {
var notification = browser.notifications.create("online_status",{
"type": "basic",
"iconUrl": browser.extension.getURL("icons/64.png"),
"title": title,
"message": "Click this message to visit the website!"
});
browser.notifications.onClicked.addListener(function() {
browser.tabs.create({"url": "http://www.url.com/" + channelName});
});
setInterval(myNotification(), 10000);
}
I just added a:
setInterval(myNotification(), 10000);
at the end of the fun function. So that if the Notification get closed after some seconds, it will spam the notification to keep it alive.
BUT the problem is, it acts like:
Open for 10 sec -> close -> reopen.... -> close -> reopen...
This is not correct aswell. I have totally no idea, how to keep the notification alive.
I really hope for some help! I just don't know what to do anymore.
I saw a Notification on YouTube. It showed me that a channel I abo uploaded a new video. THIS notification kept alive, until I clicked / closed it.
How can YouTube do it?!