Merge pull request #1536 from adriantombu/feature/sound-option

Toggle the sound notifications
This commit is contained in:
Borewit
2019-05-12 20:03:14 +02:00
committed by GitHub
5 changed files with 54 additions and 12 deletions

View File

@@ -28,6 +28,7 @@ function run (state) {
if (semver.lt(version, '0.14.0')) migrate_0_14_0(saved) if (semver.lt(version, '0.14.0')) migrate_0_14_0(saved)
if (semver.lt(version, '0.17.0')) migrate_0_17_0(saved) if (semver.lt(version, '0.17.0')) migrate_0_17_0(saved)
if (semver.lt(version, '0.17.2')) migrate_0_17_2(saved) if (semver.lt(version, '0.17.2')) migrate_0_17_2(saved)
if (semver.lt(version, '0.21.0')) migrate_0_21_0(saved)
// Config is now on the new version // Config is now on the new version
state.saved.version = config.APP_VERSION state.saved.version = config.APP_VERSION
@@ -206,3 +207,10 @@ function migrate_0_17_2 (saved) {
} catch (err) {} } catch (err) {}
} }
} }
function migrate_0_21_0 (saved) {
if (saved.prefs.soundNotifications == null) {
// The app used to always have sound notifications enabled
saved.prefs.soundNotifications = true
}
}

View File

@@ -1,4 +1,5 @@
module.exports = { module.exports = {
init,
play play
} }
@@ -8,6 +9,9 @@ const path = require('path')
const VOLUME = 0.25 const VOLUME = 0.25
// App state to access the soundNotifications preference
let state
/* Cache of Audio elements, for instant playback */ /* Cache of Audio elements, for instant playback */
const cache = {} const cache = {}
@@ -46,7 +50,15 @@ const sounds = {
} }
} }
function init (appState) {
state = appState
}
function play (name) { function play (name) {
if (!state.saved.prefs.soundNotifications) {
return
}
let audio = cache[name] let audio = cache[name]
if (!audio) { if (!audio) {
const sound = sounds[name] const sound = sounds[name]

View File

@@ -121,6 +121,7 @@ function setupStateSaved (cb) {
openExternalPlayer: false, openExternalPlayer: false,
externalPlayerPath: null, externalPlayerPath: null,
startup: false, startup: false,
soundNotifications: true,
autoAddTorrents: false, autoAddTorrents: false,
torrentsFolderPath: '', torrentsFolderPath: '',
highestPlaybackPriority: true highestPlaybackPriority: true

View File

@@ -74,6 +74,7 @@ function onState (err, _state) {
window.dispatch = dispatch window.dispatch = dispatch
telemetry.init(state) telemetry.init(state)
sound.init(state)
// Log uncaught JS errors // Log uncaught JS errors
window.addEventListener( window.addEventListener(

View File

@@ -26,6 +26,9 @@ class PreferencesPage extends React.Component {
this.handleStartupChange = this.handleStartupChange =
this.handleStartupChange.bind(this) this.handleStartupChange.bind(this)
this.handlesoundNotificationsChange =
this.handlesoundNotificationsChange.bind(this)
} }
downloadPathSelector () { downloadPathSelector () {
@@ -186,25 +189,39 @@ class PreferencesPage extends React.Component {
dispatch('updatePreferences', 'startup', isChecked) dispatch('updatePreferences', 'startup', isChecked)
} }
setStartupSection () { setStartupCheckbox () {
if (config.IS_PORTABLE) { if (config.IS_PORTABLE) {
return return
} }
return ( return (
<PreferencesSection title='Startup'>
<Preference> <Preference>
<Checkbox <Checkbox
className='control' className='control'
checked={this.props.state.saved.prefs.startup} checked={this.props.state.saved.prefs.startup}
label={'Open WebTorrent on startup.'} label={'Open WebTorrent on startup'}
onCheck={this.handleStartupChange} onCheck={this.handleStartupChange}
/> />
</Preference> </Preference>
</PreferencesSection>
) )
} }
soundNotificationsCheckbox () {
return (
<Preference>
<Checkbox
className='control'
checked={this.props.state.saved.prefs.soundNotifications}
label={'Enable sounds'}
onCheck={this.handlesoundNotificationsChange} />
</Preference>
)
}
handlesoundNotificationsChange (e, isChecked) {
dispatch('updatePreferences', 'soundNotifications', isChecked)
}
handleSetDefaultApp () { handleSetDefaultApp () {
dispatch('updatePreferences', 'isFileHandler', true) dispatch('updatePreferences', 'isFileHandler', true)
} }
@@ -230,7 +247,10 @@ class PreferencesPage extends React.Component {
<PreferencesSection title='Default torrent app'> <PreferencesSection title='Default torrent app'>
{this.setDefaultAppButton()} {this.setDefaultAppButton()}
</PreferencesSection> </PreferencesSection>
{this.setStartupSection()} <PreferencesSection title='General'>
{this.setStartupCheckbox()}
{this.soundNotificationsCheckbox()}
</PreferencesSection>
</div> </div>
) )
} }