diff --git a/src/index.js b/src/index.js index ebcd680..d17da17 100644 --- a/src/index.js +++ b/src/index.js @@ -44,3 +44,5 @@ ReactDOM.render( navigator.registerProtocolHandler("magnet", window.location.origin + "/add-torrent/%s", "Open magnet link with receptor"); + +Notification && Notification.requestPermission(); diff --git a/src/reducers/resource.js b/src/reducers/resource.js index a06f4fb..d7f0125 100644 --- a/src/reducers/resource.js +++ b/src/reducers/resource.js @@ -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: