Merge pull request #110 from feross/notifs
UX: Add interface sounds, notifications
This commit is contained in:
10
config.js
10
config.js
@@ -2,5 +2,13 @@ var path = require('path')
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
APP_NAME: 'WebTorrent',
|
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')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ function init () {
|
|||||||
|
|
||||||
// Done! Ideally we want to get here <100ms after the user clicks the app
|
// Done! Ideally we want to get here <100ms after the user clicks the app
|
||||||
document.querySelector('.loading').remove() /* TODO: no spinner once fast enough */
|
document.querySelector('.loading').remove() /* TODO: no spinner once fast enough */
|
||||||
|
playInterfaceSound(config.SOUND_STARTUP)
|
||||||
console.timeEnd('init')
|
console.timeEnd('init')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,6 +347,7 @@ function addTorrentToList (torrent) {
|
|||||||
infoHash: torrent.infoHash
|
infoHash: torrent.infoHash
|
||||||
})
|
})
|
||||||
saveState()
|
saveState()
|
||||||
|
playInterfaceSound(config.SOUND_ADD)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,6 +402,7 @@ function addTorrentEvents (torrent) {
|
|||||||
state.dock.badge += 1
|
state.dock.badge += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showDoneNotification(torrent)
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -453,10 +456,17 @@ function stopServer () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openPlayer (torrentSummary) {
|
function openPlayer (torrentSummary) {
|
||||||
|
var torrent = state.client.get(torrentSummary.infoHash)
|
||||||
|
if (!torrent || !torrent.done) playInterfaceSound(config.SOUND_PLAY)
|
||||||
torrentSummary.playStatus = 'requested'
|
torrentSummary.playStatus = 'requested'
|
||||||
|
update()
|
||||||
|
|
||||||
var timeout = setTimeout(function () {
|
var timeout = setTimeout(function () {
|
||||||
torrentSummary.playStatus = 'timeout' /* no seeders available? */
|
torrentSummary.playStatus = 'timeout' /* no seeders available? */
|
||||||
|
playInterfaceSound(config.SOUND_ERROR)
|
||||||
|
update()
|
||||||
}, 10000) /* give it a few seconds */
|
}, 10000) /* give it a few seconds */
|
||||||
|
|
||||||
startServer(torrentSummary.infoHash, function () {
|
startServer(torrentSummary.infoHash, function () {
|
||||||
// if we timed out (user clicked play a long time ago), don't autoplay
|
// if we timed out (user clicked play a long time ago), don't autoplay
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
@@ -488,9 +498,11 @@ function toggleTorrent (torrentSummary) {
|
|||||||
if (torrentSummary.status === 'paused') {
|
if (torrentSummary.status === 'paused') {
|
||||||
torrentSummary.status = 'new'
|
torrentSummary.status = 'new'
|
||||||
startTorrenting(torrentSummary.infoHash)
|
startTorrenting(torrentSummary.infoHash)
|
||||||
|
playInterfaceSound(config.SOUND_ENABLE)
|
||||||
} else {
|
} else {
|
||||||
torrentSummary.status = 'paused'
|
torrentSummary.status = 'paused'
|
||||||
stopTorrenting(torrentSummary.infoHash)
|
stopTorrenting(torrentSummary.infoHash)
|
||||||
|
playInterfaceSound(config.SOUND_DISABLE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,6 +514,7 @@ function deleteTorrent (torrentSummary) {
|
|||||||
var index = state.saved.torrents.findIndex((x) => x.infoHash === infoHash)
|
var index = state.saved.torrents.findIndex((x) => x.infoHash === infoHash)
|
||||||
if (index > -1) state.saved.torrents.splice(index, 1)
|
if (index > -1) state.saved.torrents.splice(index, 1)
|
||||||
saveState()
|
saveState()
|
||||||
|
playInterfaceSound(config.SOUND_DELETE)
|
||||||
}
|
}
|
||||||
|
|
||||||
function openChromecast (infoHash) {
|
function openChromecast (infoHash) {
|
||||||
@@ -565,9 +578,33 @@ function restoreBounds () {
|
|||||||
function onError (err) {
|
function onError (err) {
|
||||||
console.error(err.stack)
|
console.error(err.stack)
|
||||||
window.alert(err.message || err)
|
window.alert(err.message || err)
|
||||||
|
playInterfaceSound(config.SOUND_ERROR)
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onWarning (err) {
|
function onWarning (err) {
|
||||||
console.log('warning: %s', err.message)
|
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()
|
||||||
|
}
|
||||||
|
|||||||
BIN
resources/sound/add.wav
Normal file
BIN
resources/sound/add.wav
Normal file
Binary file not shown.
BIN
resources/sound/delete.wav
Normal file
BIN
resources/sound/delete.wav
Normal file
Binary file not shown.
BIN
resources/sound/disable.wav
Normal file
BIN
resources/sound/disable.wav
Normal file
Binary file not shown.
BIN
resources/sound/done.wav
Normal file
BIN
resources/sound/done.wav
Normal file
Binary file not shown.
BIN
resources/sound/enable.wav
Normal file
BIN
resources/sound/enable.wav
Normal file
Binary file not shown.
BIN
resources/sound/error.wav
Normal file
BIN
resources/sound/error.wav
Normal file
Binary file not shown.
BIN
resources/sound/play.wav
Normal file
BIN
resources/sound/play.wav
Normal file
Binary file not shown.
BIN
resources/sound/startup.wav
Normal file
BIN
resources/sound/startup.wav
Normal file
Binary file not shown.
Reference in New Issue
Block a user