From c9da5b80780bfbc7855ab7d2e716ce12756f64ed Mon Sep 17 00:00:00 2001 From: Abhinav Adduri Date: Wed, 21 Jun 2017 13:23:36 -0700 Subject: [PATCH] added notifications --- frontend/src/download.js | 2 ++ frontend/src/fileSender.js | 4 ++-- frontend/src/upload.js | 4 ++++ frontend/src/utils.js | 16 +++++++++++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/frontend/src/download.js b/frontend/src/download.js index 5ad2fb3e..05abb64b 100644 --- a/frontend/src/download.js +++ b/frontend/src/download.js @@ -1,4 +1,5 @@ const FileReceiver = require('./fileReceiver'); +const { notify } = require('./utils'); const $ = require('jquery'); $(document).ready(function() { @@ -16,6 +17,7 @@ $(document).ready(function() { if (percentComplete === 100) { fileReceiver.removeAllListeners('progress'); + notify('Your download has finished.'); btn.text('Download complete!'); btn.attr('disabled', 'true'); } diff --git a/frontend/src/fileSender.js b/frontend/src/fileSender.js index 8a70c2f9..fea1daf2 100644 --- a/frontend/src/fileSender.js +++ b/frontend/src/fileSender.js @@ -1,5 +1,5 @@ const EventEmitter = require('events'); -const { ivToStr } = require('./utils'); +const { ivToStr, notify } = require('./utils'); class FileSender extends EventEmitter { constructor(file) { @@ -23,7 +23,7 @@ class FileSender extends EventEmitter { } if (xhr.status === 200) { - console.log('The file was successfully deleted.'); + console.log('The file was successfully deleted.') } else { console.log('The file has expired, or has already been deleted.'); } diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 17d4a3b8..96159ded 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -1,4 +1,5 @@ const FileSender = require('./fileSender'); +const { notify } = require('./utils') const $ = require('jquery'); $(document).ready(function() { @@ -84,6 +85,9 @@ $(document).ready(function() { $('#upload-progress').show(); $('#upload-filename').innerHTML += file.name; progress.innerText = `Progress: ${percentComplete}%`; + if (percentComplete === 100) { + notify('Your upload has finished.'); + } }); fileSender.upload().then(info => { const url = info.url.trim() + `#${info.secretKey}`.trim(); diff --git a/frontend/src/utils.js b/frontend/src/utils.js index a95026f8..3c504705 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -20,7 +20,21 @@ function strToIv(str) { return iv; } +function notify(str) { + if (!("Notification" in window)) { + return; + } else if (Notification.permission === 'granted') { + new Notification(str) + } else if (Notification.permission !== 'denied') { + Notification.requestPermission(function(permission) { + if (permission === 'granted') + new Notification(str); + }) + } +} + module.exports = { ivToStr, - strToIv + strToIv, + notify };