UX: Add interface sounds
This commit is contained in:
10
config.js
10
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')
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,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)
|
||||
@@ -489,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,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) {
|
||||
@@ -566,6 +578,7 @@ function restoreBounds () {
|
||||
function onError (err) {
|
||||
console.error(err.stack)
|
||||
window.alert(err.message || err)
|
||||
playInterfaceSound(config.SOUND_ERROR)
|
||||
update()
|
||||
}
|
||||
|
||||
@@ -578,10 +591,20 @@ function showDoneNotification (torrent) {
|
||||
if (state.window.isFocused) return
|
||||
|
||||
var notif = new window.Notification('Download Complete', {
|
||||
body: torrent.name
|
||||
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