bg gamechat notifications

This commit is contained in:
ITZVGcGPmO 2019-05-21 11:58:16 -07:00 committed by GitHub
parent 8e1c5e805b
commit 6ec5284dfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -135,3 +135,24 @@ cah.updateHash = function(hash) {
window.location.replace(window.location.protocol + '//' + window.location.host
+ window.location.pathname.replace(/#$/g, '') + '#' + hash);
};
/**
* Sends notifications, when the window is not in focus
*
* @notifcont {String}
* string A string to notify to the user
*/
cah.notifyBg = function(notifcont) {
if ("Notification" in window) { // if browser supports notifications
// If it's okay let's create a notification
if (Notification.permission === "granted" && !(document.hasFocus())) {
var notification = new Notification(notifcont);
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== "denied") {
Notification.requestPermission();
}
}
}

View File

@ -83,6 +83,7 @@ cah.log.status_with_game = function(game_or_id, text, opt_class, opt_allow_html,
if (game_or_id === null || game_or_id === undefined) {
logElement = cah.log.log;
} else {
cah.notifyBg(text); // send notifications of game chat, when in bg
var game;
if (game_or_id instanceof cah.Game) {
game = game_or_id;