From 538bf77cbecb96d6f3771ec99ccb6f34ec5ef005 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Mar 22 2020 10:21:36 +0000 Subject: added browser notifications --- diff --git a/themes/default/public/js/lufi-down.js b/themes/default/public/js/lufi-down.js index 4108df9..1560d3e 100644 --- a/themes/default/public/js/lufi-down.js +++ b/themes/default/public/js/lufi-down.js @@ -95,6 +95,7 @@ function spawnWebsocket(pa) { if (data.part + 1 === data.total) { var blob = new Blob(a, {type: data.type}); + notify('File downloaded', data.name); $('#please-wait').remove(); $('#loading').remove(); diff --git a/themes/default/public/js/lufi-notifications.js b/themes/default/public/js/lufi-notifications.js new file mode 100644 index 0000000..7a8d221 --- /dev/null +++ b/themes/default/public/js/lufi-notifications.js @@ -0,0 +1,24 @@ +function notify(title, body) { + if (!Notification) { + return; + } + + if (Notification.permission !== "granted") { + Notification.requestPermission(); + } else { + let options = { + body: body, + icon: '/img/lufi196.png' + }; + let n = new Notification(title, options); + } +} + +document.addEventListener('DOMContentLoaded', function () { + if (!Notification) { + return; + } + + if (Notification.permission !== "granted") + Notification.requestPermission(); +}); \ No newline at end of file diff --git a/themes/default/public/js/lufi-up.js b/themes/default/public/js/lufi-up.js index e7ae260..2cb1050 100644 --- a/themes/default/public/js/lufi-up.js +++ b/themes/default/public/js/lufi-up.js @@ -477,6 +477,8 @@ function updateProgressBar(data) { console.log('Error on WebSocket connection but file has been fully send, so we don\'t care.'); } + notify('File uploaded', data.name); + $('#parts-'+window.fc).remove(); var n = $('#name-'+window.fc); var s = $('#size-'+window.fc); diff --git a/themes/default/templates/index.html.ep b/themes/default/templates/index.html.ep index 9f498c2..6409f78 100644 --- a/themes/default/templates/index.html.ep +++ b/themes/default/templates/index.html.ep @@ -165,5 +165,6 @@ %= javascript '/js/moment-with-locales.min.js' %= javascript '/js/filesize.min.js' %= javascript '/js/jszip.min.js' +%= javascript '/js/lufi-notifications.js' %= javascript '/js/lufi-up.js' % } diff --git a/themes/default/templates/render.html.ep b/themes/default/templates/render.html.ep index 4c06596..9deb809 100644 --- a/themes/default/templates/render.html.ep +++ b/themes/default/templates/render.html.ep @@ -45,6 +45,7 @@ %= javascript '/js/filesize.min.js' %= javascript '/js/sjcl.js' %= javascript '/js/jszip.min.js' +%= javascript '/js/lufi-notifications.js' %= javascript '/js/lufi-down.js' % } % }