client/js: clearer state machine for html5 notification permissions

This commit is contained in:
mappu 2017-02-06 11:58:21 +13:00
parent d2b1d23ba6
commit 692537c6f0

View File

@ -151,16 +151,22 @@ var notify = function(title, body) {
return; // not supported by browser return; // not supported by browser
} }
if (window.Notification.permission === "granted") { switch (window.Notification.permission) {
var nn = new Notification(title, { case "granted": {
body: body, new Notification(title, {
icon: DCWEBUI_CONF.extern + "/favicon.ico" body: body,
}); icon: DCWEBUI_CONF.extern + "/favicon.ico"
});
} break;
} else if (window.Notification.permission !== "denied") { case "denied": return;
Notification.requestPermission(function(permission) {
notify(title, body); default: {
}); // Clarify permission and retry
Notification.requestPermission(function(permission) {
notify(title, body);
});
} break;
} }
}; };