mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Check browser has notification capability
This commit is contained in:
parent
175bb9e5c7
commit
88416fcd54
@ -1,7 +1,9 @@
|
|||||||
class Notifications {
|
class Notifications {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
if (this.notifications_available) {
|
||||||
Notification.requestPermission();
|
Notification.requestPermission();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
notifyTurn(player) {
|
notifyTurn(player) {
|
||||||
this.notify({
|
this.notify({
|
||||||
@ -11,10 +13,14 @@ class Notifications {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notify(options) {
|
notify(options) {
|
||||||
if (!document.hasFocus()) {
|
if (this.notifications_available && !document.hasFocus()) {
|
||||||
new Notification("Chess", options);
|
new Notification("Chess", options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get notifications_available() {
|
||||||
|
window.Notification != undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Notifications;
|
export default Notifications;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user