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