From 97cf38e5012cca2e6d745c9805417709e75aea21 Mon Sep 17 00:00:00 2001 From: Adrian Tombu Date: Sat, 12 Jan 2019 12:54:06 +0100 Subject: [PATCH] Toggle the sound notifications --- src/renderer/lib/sound.js | 12 ++++++++++++ src/renderer/lib/state.js | 1 + src/renderer/main.js | 1 + src/renderer/pages/preferences-page.js | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/src/renderer/lib/sound.js b/src/renderer/lib/sound.js index a31aa2ce..0bcfe077 100644 --- a/src/renderer/lib/sound.js +++ b/src/renderer/lib/sound.js @@ -1,4 +1,5 @@ module.exports = { + init, play } @@ -8,6 +9,9 @@ const path = require('path') const VOLUME = 0.25 +// App state to access the soundNotifications preference +let state + /* Cache of Audio elements, for instant playback */ const cache = {} @@ -46,7 +50,15 @@ const sounds = { } } +function init (appState) { + state = appState +} + function play (name) { + if (!state.saved.prefs.soundNotifications) { + return + } + let audio = cache[name] if (!audio) { const sound = sounds[name] diff --git a/src/renderer/lib/state.js b/src/renderer/lib/state.js index 0a554772..4ac7f34a 100644 --- a/src/renderer/lib/state.js +++ b/src/renderer/lib/state.js @@ -121,6 +121,7 @@ function setupStateSaved (cb) { openExternalPlayer: false, externalPlayerPath: null, startup: false, + soundNotifications: true, autoAddTorrents: false, torrentsFolderPath: '', highestPlaybackPriority: true diff --git a/src/renderer/main.js b/src/renderer/main.js index 887fb4db..4d9d18ef 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -74,6 +74,7 @@ function onState (err, _state) { window.dispatch = dispatch telemetry.init(state) + sound.init(state) // Log uncaught JS errors window.addEventListener( diff --git a/src/renderer/pages/preferences-page.js b/src/renderer/pages/preferences-page.js index 687af900..96df6f98 100644 --- a/src/renderer/pages/preferences-page.js +++ b/src/renderer/pages/preferences-page.js @@ -26,6 +26,9 @@ class PreferencesPage extends React.Component { this.handleStartupChange = this.handleStartupChange.bind(this) + + this.handlesoundNotificationsChange = + this.handlesoundNotificationsChange.bind(this) } downloadPathSelector () { @@ -205,6 +208,22 @@ class PreferencesPage extends React.Component { ) } + soundNotificationsCheckbox () { + return ( + + + + ) + } + + handlesoundNotificationsChange (e, isChecked) { + dispatch('updatePreferences', 'soundNotifications', isChecked) + } + handleSetDefaultApp () { dispatch('updatePreferences', 'isFileHandler', true) } @@ -231,6 +250,9 @@ class PreferencesPage extends React.Component { {this.setDefaultAppButton()} {this.setStartupSection()} + + {this.soundNotificationsCheckbox()} + ) }