Browser notifications !

This commit is contained in:
Alexandre Aubin 2021-03-01 23:33:17 +01:00
parent 1fd5a437ab
commit 60baaaabd2
3 changed files with 49 additions and 0 deletions

View file

@ -343,3 +343,41 @@ var AnsiUp = (function () {
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = AnsiUp;
}));
function notify(message) {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
return;
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(
"Yunohost Apps CI",
{
icon: "https://yunohost.org/_images/yunohost_package.png",
body: message
}
);
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== "denied") {
Notification.requestPermission().then(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(
"Yunohost Apps CI",
{
icon: "https://yunohost.org/_images/yunohost_package.png",
body: message
}
);
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}

View file

@ -72,6 +72,12 @@
for (var i = 0; i < app.jobs.length; ++i) {
if (app.jobs[i].id == data.id) {
Vue.set(app.jobs, i, data);
if ((app.jobs[i].state !== undefined) && (app.jobs[i].state != data.state))
{
notify("Job for " + data.name + " is " + data.state);
}
break;
}
}

View file

@ -75,6 +75,11 @@
var action = message.action;
if (action == "init_job" || action == "update_job") {
if ((app.job.state !== undefined) && (app.job.state != data.state))
{
notify("Job for " + data.name + " is " + data.state);
}
data.deleted = false;
app.job = data;
} else if (action == "delete_job") {