Merge pull request #13322 from dannon/notification-compat

[22.01] Ensure Notification API is available prior to trying to use it
This commit is contained in:
Marius van den Beek
2022-02-08 11:14:59 +01:00
committed by GitHub
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");
}
}
}
}