Add download notifications

Fixes #16
This commit is contained in:
Drew DeVault 2017-12-29 14:56:41 -05:00
parent 14b9d1b592
commit 45f7c94931
2 changed files with 12 additions and 1 deletions

View File

@ -44,3 +44,5 @@ ReactDOM.render(
navigator.registerProtocolHandler("magnet",
window.location.origin + "/add-torrent/%s",
"Open magnet link with receptor");
Notification && Notification.requestPermission();

View File

@ -1,6 +1,15 @@
import { UPDATE_RESOURCES, RESOURCES_REMOVED } from '../actions/resources';
import { SOCKET_STATE, SOCKET_UPDATE } from '../actions/socket';
function hack(old, _new) {
if (old && old.type == "torrent") {
if (old.progress != 1 && _new.progress == 1) {
Notification && new Notification("Download complete: " + _new.name);
}
}
return _new;
}
export default function resourceReducer(type) {
return (state = {}, action) => {
switch (action.type) {
@ -11,7 +20,7 @@ export default function resourceReducer(type) {
.filter(r => r.type === type)
.reduce((s, r) => ({
...s,
[r.id]: { ...state[r.id], ...r }
[r.id]: hack(state[r.id], { ...state[r.id], ...r })
}), {})
};
case RESOURCES_REMOVED: