1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-11 05:32:40 +01:00

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 { 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');
}

View File

@ -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.');
}

View File

@ -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();

View File

@ -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
};