Files
transmission/web/javascript/notifications.js
Charles Kerr be219ddee0 chore: add precommit hook for testing code style (#1448)
* chore: add precommit hook for testing code style

* chore: use prettier + eslint for js code
2020-09-13 21:41:32 -05:00

47 lines
1.3 KiB
JavaScript

const Notifications = {};
$(document).ready(function () {
if (!window.webkitNotifications) {
return;
}
let notificationsEnabled = window.webkitNotifications.checkPermission() === 0;
const toggle = $('#toggle_notifications');
toggle.show();
updateMenuTitle();
$(transmission).bind('downloadComplete seedingComplete', function (event, torrent) {
if (notificationsEnabled) {
let 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();
}
};
});