Add a check to see if the Notification API is available prior to trying

to configure or send them.
This commit is contained in:
Dannon Baker
2022-02-07 20:38:28 -05:00
parent 377a608c5c
commit e6e4ae4030
2 changed files with 28 additions and 18 deletions
+14 -10
View File
@@ -177,16 +177,20 @@ export default {
},
methods: {
toggleNotifications() {
Notification.requestPermission().then(function (permission) {
//If the user accepts, let's create a notification
if (permission === "granted") {
new Notification("Notifications enabled", {
icon: "static/favicon.ico",
});
} else {
alert("Notifications disabled, please re-enable through browser settings.");
}
});
if (window.Notification) {
Notification.requestPermission().then(function (permission) {
//If the user accepts, let's create a notification
if (permission === "granted") {
new Notification("Notifications enabled", {
icon: "static/favicon.ico",
});
} else {
alert("Notifications disabled, please re-enable through browser settings.");
}
});
} else {
alert("Notifications are not supported by this browser.");
}
},
openManageCustomBuilds() {
const Galaxy = getGalaxyInstance();
+14 -8
View File
@@ -103,19 +103,25 @@ var DatasetAssociation = Backbone.Model.extend(BASE_MVC.LoggableMixin).extend(
this.trigger("state:ready", currModel, newState, this.previous("state"));
if (newState != "discarded") {
if (newState === "ok") {
new Notification(`Job complete: ${this.get("name")}`, {
icon: "static/favicon.ico",
});
// If Notifications are supported, send one.
if (window.Notification) {
new Notification(`Job complete: ${this.get("name")}`, {
icon: "static/favicon.ico",
});
}
if (TAB_UPDATES.is_hidden()) {
TAB_UPDATES.hidden_count(hiddenupdates);
hiddenupdates++;
}
} else if (newState == "error") {
new Notification(`Job failure: ${this.get("name")}`, {
icon: "static/erricon.ico",
});
if (TAB_UPDATES.is_hidden() && Notification.permission == "granted") {
TAB_UPDATES.change_favicon("static/erricon.ico");
// If Notifications are supported, send one.
if (window.Notification) {
new Notification(`Job failure: ${this.get("name")}`, {
icon: "static/erricon.ico",
});
if (TAB_UPDATES.is_hidden() && Notification.permission == "granted") {
TAB_UPDATES.change_favicon("static/erricon.ico");
}
}
}
}