ludei / atomic-plugins-notifications

2 stars 2 forks source link

Initialization bug in cocoon_notifications.js #2

Open nikoladev opened 8 years ago

nikoladev commented 8 years ago

The callback in this example from the README always sends out the alert that notifications are disabled:

Cocoon.Notification.Local.initialize({}, function(registered) {
    if (!registered) {
        alert('Notifications disabled by user')
    }
    else {
        sendNotification(); 
    }
})

This is because there's a bug in line 130 of cocoon_notifications.js that ensures that registered is always false: https://github.com/ludei/atomic-plugins-notifications/blob/master/src/js/cocoon_notifications.js#L130

Until that bug is fixed, this is a workaround that should work:

Cocoon.Notification.Local.initialize({}, function (registered) {
    Cocoon.Notification.Local.isRegistered(function (granted) {
        if (!granted) {
            alert('Notifications disabled by user');
        } else {
            sendNotification();
        }
    });
});