diff --git a/config.js b/config.js index d8e90215..b8759c51 100644 --- a/config.js +++ b/config.js @@ -2,5 +2,13 @@ var path = require('path') module.exports = { APP_NAME: 'WebTorrent', - INDEX: 'file://' + path.resolve(__dirname, 'renderer', 'index.html') + INDEX: 'file://' + path.resolve(__dirname, 'renderer', 'index.html'), + SOUND_ADD: 'file://' + path.resolve(__dirname, 'resources', 'sound', 'add.wav'), + SOUND_DELETE: 'file://' + path.resolve(__dirname, 'resources', 'sound', 'delete.wav'), + SOUND_DISABLE: 'file://' + path.resolve(__dirname, 'resources', 'sound', 'disable.wav'), + SOUND_DONE: 'file://' + path.resolve(__dirname, 'resources', 'sound', 'done.wav'), + SOUND_ENABLE: 'file://' + path.resolve(__dirname, 'resources', 'sound', 'enable.wav'), + SOUND_ERROR: 'file://' + path.resolve(__dirname, 'resources', 'sound', 'error.wav'), + SOUND_PLAY: 'file://' + path.resolve(__dirname, 'resources', 'sound', 'play.wav'), + SOUND_STARTUP: 'file://' + path.resolve(__dirname, 'resources', 'sound', 'startup.wav') } diff --git a/renderer/index.js b/renderer/index.js index 112f3381..6458274c 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -118,6 +118,7 @@ function init () { // Done! Ideally we want to get here <100ms after the user clicks the app document.querySelector('.loading').remove() /* TODO: no spinner once fast enough */ + playInterfaceSound(config.SOUND_STARTUP) console.timeEnd('init') } @@ -346,6 +347,7 @@ function addTorrentToList (torrent) { infoHash: torrent.infoHash }) saveState() + playInterfaceSound(config.SOUND_ADD) } } @@ -400,6 +402,7 @@ function addTorrentEvents (torrent) { state.dock.badge += 1 } + showDoneNotification(torrent) update() } } @@ -453,10 +456,17 @@ function stopServer () { } function openPlayer (torrentSummary) { + var torrent = state.client.get(torrentSummary.infoHash) + if (!torrent || !torrent.done) playInterfaceSound(config.SOUND_PLAY) torrentSummary.playStatus = 'requested' + update() + var timeout = setTimeout(function () { torrentSummary.playStatus = 'timeout' /* no seeders available? */ + playInterfaceSound(config.SOUND_ERROR) + update() }, 10000) /* give it a few seconds */ + startServer(torrentSummary.infoHash, function () { // if we timed out (user clicked play a long time ago), don't autoplay clearTimeout(timeout) @@ -488,9 +498,11 @@ function toggleTorrent (torrentSummary) { if (torrentSummary.status === 'paused') { torrentSummary.status = 'new' startTorrenting(torrentSummary.infoHash) + playInterfaceSound(config.SOUND_ENABLE) } else { torrentSummary.status = 'paused' stopTorrenting(torrentSummary.infoHash) + playInterfaceSound(config.SOUND_DISABLE) } } @@ -502,6 +514,7 @@ function deleteTorrent (torrentSummary) { var index = state.saved.torrents.findIndex((x) => x.infoHash === infoHash) if (index > -1) state.saved.torrents.splice(index, 1) saveState() + playInterfaceSound(config.SOUND_DELETE) } function openChromecast (infoHash) { @@ -565,9 +578,33 @@ function restoreBounds () { function onError (err) { console.error(err.stack) window.alert(err.message || err) + playInterfaceSound(config.SOUND_ERROR) update() } function onWarning (err) { console.log('warning: %s', err.message) } + +function showDoneNotification (torrent) { + console.log(state.window.isFocused) + if (state.window.isFocused) return + + var notif = new window.Notification('Download Complete', { + body: torrent.name, + silent: true + }) + + notif.onclick = function () { + window.focus() + } + + playInterfaceSound(config.SOUND_DONE) +} + +function playInterfaceSound (url) { + var audio = new window.Audio() + audio.volume = 0.3 + audio.src = url + audio.play() +} diff --git a/resources/sound/add.wav b/resources/sound/add.wav new file mode 100644 index 00000000..83482af4 Binary files /dev/null and b/resources/sound/add.wav differ diff --git a/resources/sound/delete.wav b/resources/sound/delete.wav new file mode 100644 index 00000000..7884d766 Binary files /dev/null and b/resources/sound/delete.wav differ diff --git a/resources/sound/disable.wav b/resources/sound/disable.wav new file mode 100644 index 00000000..b629f766 Binary files /dev/null and b/resources/sound/disable.wav differ diff --git a/resources/sound/done.wav b/resources/sound/done.wav new file mode 100644 index 00000000..6eef77af Binary files /dev/null and b/resources/sound/done.wav differ diff --git a/resources/sound/enable.wav b/resources/sound/enable.wav new file mode 100644 index 00000000..fefc652b Binary files /dev/null and b/resources/sound/enable.wav differ diff --git a/resources/sound/error.wav b/resources/sound/error.wav new file mode 100644 index 00000000..4ab36c1d Binary files /dev/null and b/resources/sound/error.wav differ diff --git a/resources/sound/play.wav b/resources/sound/play.wav new file mode 100644 index 00000000..b6f27773 Binary files /dev/null and b/resources/sound/play.wav differ diff --git a/resources/sound/startup.wav b/resources/sound/startup.wav new file mode 100644 index 00000000..dbc825ae Binary files /dev/null and b/resources/sound/startup.wav differ