Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle the sound notifications #1536

Merged
merged 3 commits into from
May 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/renderer/lib/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function run (state) {
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.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
state.saved.version = config.APP_VERSION
Expand Down Expand Up @@ -206,3 +207,10 @@ function migrate_0_17_2 (saved) {
} 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
}
}
12 changes: 12 additions & 0 deletions src/renderer/lib/sound.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
init,
play
}

Expand All @@ -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 = {}

Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/renderer/lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function setupStateSaved (cb) {
openExternalPlayer: false,
externalPlayerPath: null,
startup: false,
soundNotifications: true,
autoAddTorrents: false,
torrentsFolderPath: '',
highestPlaybackPriority: true
Expand Down
1 change: 1 addition & 0 deletions src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function onState (err, _state) {
window.dispatch = dispatch

telemetry.init(state)
sound.init(state)

// Log uncaught JS errors
window.addEventListener(
Expand Down
44 changes: 32 additions & 12 deletions src/renderer/pages/preferences-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class PreferencesPage extends React.Component {

this.handleStartupChange =
this.handleStartupChange.bind(this)

this.handlesoundNotificationsChange =
this.handlesoundNotificationsChange.bind(this)
}

downloadPathSelector () {
Expand Down Expand Up @@ -186,25 +189,39 @@ class PreferencesPage extends React.Component {
dispatch('updatePreferences', 'startup', isChecked)
}

setStartupSection () {
setStartupCheckbox () {
if (config.IS_PORTABLE) {
return
}

return (
<PreferencesSection title='Startup'>
<Preference>
<Checkbox
className='control'
checked={this.props.state.saved.prefs.startup}
label={'Open WebTorrent on startup.'}
onCheck={this.handleStartupChange}
/>
</Preference>
</PreferencesSection>
<Preference>
<Checkbox
className='control'
checked={this.props.state.saved.prefs.startup}
label={'Open WebTorrent on startup'}
onCheck={this.handleStartupChange}
/>
</Preference>
)
}

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 () {
dispatch('updatePreferences', 'isFileHandler', true)
}
Expand All @@ -230,7 +247,10 @@ class PreferencesPage extends React.Component {
<PreferencesSection title='Default torrent app'>
{this.setDefaultAppButton()}
</PreferencesSection>
{this.setStartupSection()}
<PreferencesSection title='General'>
{this.setStartupCheckbox()}
{this.soundNotificationsCheckbox()}
</PreferencesSection>
</div>
)
}
Expand Down