Merge pull request #110 from mozilla/notify-clean

added notifications
This commit is contained in:
Abhinav Adduri 2017-06-21 13:38:28 -07:00 committed by GitHub
commit cfd2883db5
4 changed files with 23 additions and 3 deletions

View file

@ -1,4 +1,5 @@
const FileReceiver = require('./fileReceiver'); const FileReceiver = require('./fileReceiver');
const { notify } = require('./utils');
const $ = require('jquery'); const $ = require('jquery');
$(document).ready(function() { $(document).ready(function() {
@ -16,6 +17,7 @@ $(document).ready(function() {
if (percentComplete === 100) { if (percentComplete === 100) {
fileReceiver.removeAllListeners('progress'); fileReceiver.removeAllListeners('progress');
notify('Your download has finished.');
btn.text('Download complete!'); btn.text('Download complete!');
btn.attr('disabled', 'true'); btn.attr('disabled', 'true');
} }

View file

@ -1,5 +1,5 @@
const EventEmitter = require('events'); const EventEmitter = require('events');
const { ivToStr } = require('./utils'); const { ivToStr, notify } = require('./utils');
class FileSender extends EventEmitter { class FileSender extends EventEmitter {
constructor(file) { constructor(file) {
@ -23,7 +23,7 @@ class FileSender extends EventEmitter {
} }
if (xhr.status === 200) { if (xhr.status === 200) {
console.log('The file was successfully deleted.'); console.log('The file was successfully deleted.')
} else { } else {
console.log('The file has expired, or has already been deleted.'); console.log('The file has expired, or has already been deleted.');
} }

View file

@ -1,4 +1,5 @@
const FileSender = require('./fileSender'); const FileSender = require('./fileSender');
const { notify } = require('./utils')
const $ = require('jquery'); const $ = require('jquery');
$(document).ready(function() { $(document).ready(function() {
@ -84,6 +85,9 @@ $(document).ready(function() {
$('#upload-progress').show(); $('#upload-progress').show();
$('#upload-filename').innerHTML += file.name; $('#upload-filename').innerHTML += file.name;
progress.innerText = `Progress: ${percentComplete}%`; progress.innerText = `Progress: ${percentComplete}%`;
if (percentComplete === 100) {
notify('Your upload has finished.');
}
}); });
fileSender.upload().then(info => { fileSender.upload().then(info => {
const url = info.url.trim() + `#${info.secretKey}`.trim(); const url = info.url.trim() + `#${info.secretKey}`.trim();

View file

@ -20,7 +20,21 @@ function strToIv(str) {
return iv; 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 = { module.exports = {
ivToStr, ivToStr,
strToIv strToIv,
notify
}; };