Toggle the sound notifications
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -121,6 +121,7 @@ function setupStateSaved (cb) {
|
||||
openExternalPlayer: false,
|
||||
externalPlayerPath: null,
|
||||
startup: false,
|
||||
soundNotifications: true,
|
||||
autoAddTorrents: false,
|
||||
torrentsFolderPath: '',
|
||||
highestPlaybackPriority: true
|
||||
|
||||
@@ -74,6 +74,7 @@ function onState (err, _state) {
|
||||
window.dispatch = dispatch
|
||||
|
||||
telemetry.init(state)
|
||||
sound.init(state)
|
||||
|
||||
// Log uncaught JS errors
|
||||
window.addEventListener(
|
||||
|
||||
@@ -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 (
|
||||
<Preference>
|
||||
<Checkbox
|
||||
className='control'
|
||||
checked={this.props.state.saved.prefs.soundNotifications}
|
||||
label={'Activate the notification sounds'}
|
||||
onCheck={this.handlesoundNotificationsChange} />
|
||||
</Preference>
|
||||
)
|
||||
}
|
||||
|
||||
handlesoundNotificationsChange (e, isChecked) {
|
||||
dispatch('updatePreferences', 'soundNotifications', isChecked)
|
||||
}
|
||||
|
||||
handleSetDefaultApp () {
|
||||
dispatch('updatePreferences', 'isFileHandler', true)
|
||||
}
|
||||
@@ -231,6 +250,9 @@ class PreferencesPage extends React.Component {
|
||||
{this.setDefaultAppButton()}
|
||||
</PreferencesSection>
|
||||
{this.setStartupSection()}
|
||||
<PreferencesSection title='Miscellaneous'>
|
||||
{this.soundNotificationsCheckbox()}
|
||||
</PreferencesSection>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user