From 45f7c949313d552a052413bfc4a43fe5006a5aae Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 29 Dec 2017 14:56:41 -0500 Subject: [PATCH] Add download notifications Fixes #16 --- src/index.js | 2 ++ src/reducers/resource.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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: