2012-05-19 21:37:29 +00:00
|
|
|
var Notifications = {};
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
2016-03-10 19:05:13 +00:00
|
|
|
if (!window.webkitNotifications) {
|
|
|
|
return;
|
|
|
|
};
|
2012-05-19 21:37:29 +00:00
|
|
|
|
2016-03-10 19:05:13 +00:00
|
|
|
var notificationsEnabled = (window.webkitNotifications.checkPermission() === 0)
|
|
|
|
var toggle = $('#toggle_notifications');
|
2012-05-19 21:37:29 +00:00
|
|
|
|
2016-03-10 19:05:13 +00:00
|
|
|
toggle.show();
|
|
|
|
updateMenuTitle();
|
|
|
|
$(transmission).bind('downloadComplete seedingComplete', function (event, torrent) {
|
|
|
|
if (notificationsEnabled) {
|
|
|
|
var title = (event.type == 'downloadComplete' ? 'Download' : 'Seeding') + ' complete',
|
|
|
|
content = torrent.getName(),
|
|
|
|
notification;
|
2015-05-05 19:12:48 +00:00
|
|
|
|
2016-03-10 19:05:13 +00:00
|
|
|
notification = window.webkitNotifications.createNotification('style/transmission/images/logo.png', title, content);
|
|
|
|
notification.show();
|
|
|
|
setTimeout(function () {
|
|
|
|
notification.cancel();
|
|
|
|
}, 5000);
|
|
|
|
};
|
|
|
|
});
|
2012-05-19 21:37:29 +00:00
|
|
|
|
2016-03-10 19:05:13 +00:00
|
|
|
function updateMenuTitle() {
|
|
|
|
toggle.html((notificationsEnabled ? 'Disable' : 'Enable') + ' Notifications');
|
|
|
|
};
|
2012-05-19 21:37:29 +00:00
|
|
|
|
2016-03-10 19:05:13 +00:00
|
|
|
Notifications.toggle = function () {
|
|
|
|
if (window.webkitNotifications.checkPermission() !== 0) {
|
|
|
|
window.webkitNotifications.requestPermission(function () {
|
|
|
|
notificationsEnabled = (window.webkitNotifications.checkPermission() === 0);
|
|
|
|
updateMenuTitle();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
notificationsEnabled = !notificationsEnabled;
|
|
|
|
updateMenuTitle();
|
|
|
|
};
|
|
|
|
};
|
2015-05-05 19:12:48 +00:00
|
|
|
});
|