1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-30 19:46:56 +00:00
transmission/web/javascript/notifications.js
2016-03-10 19:05:13 +00:00

42 lines
1.4 KiB
JavaScript

var Notifications = {};
$(document).ready(function () {
if (!window.webkitNotifications) {
return;
};
var notificationsEnabled = (window.webkitNotifications.checkPermission() === 0)
var toggle = $('#toggle_notifications');
toggle.show();
updateMenuTitle();
$(transmission).bind('downloadComplete seedingComplete', function (event, torrent) {
if (notificationsEnabled) {
var title = (event.type == 'downloadComplete' ? 'Download' : 'Seeding') + ' complete',
content = torrent.getName(),
notification;
notification = window.webkitNotifications.createNotification('style/transmission/images/logo.png', title, content);
notification.show();
setTimeout(function () {
notification.cancel();
}, 5000);
};
});
function updateMenuTitle() {
toggle.html((notificationsEnabled ? 'Disable' : 'Enable') + ' Notifications');
};
Notifications.toggle = function () {
if (window.webkitNotifications.checkPermission() !== 0) {
window.webkitNotifications.requestPermission(function () {
notificationsEnabled = (window.webkitNotifications.checkPermission() === 0);
updateMenuTitle();
});
} else {
notificationsEnabled = !notificationsEnabled;
updateMenuTitle();
};
};
});