From f954a1e7bccfd26259fe246e885f195fb51fdea6 Mon Sep 17 00:00:00 2001 From: Albin Ekblom Date: Sat, 6 Aug 2016 00:30:40 +0200 Subject: [PATCH] Add config for bell (#468) * Add config for bell * Use Set instead --- app/config-default.js | 8 +++++++- lib/components/term.js | 12 ++++++++++++ lib/components/terms.js | 4 +++- lib/containers/terms.js | 4 +++- lib/reducers/ui.js | 17 ++++++++++++++--- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/app/config-default.js b/app/config-default.js index bf51c8f8..d56a7fb1 100644 --- a/app/config-default.js +++ b/app/config-default.js @@ -57,7 +57,13 @@ module.exports = { shell: '', // for environment variables - env: {} + env: {}, + + // set to false for no bell + bell: 'SOUND' + + // URL to custom bell + // bellSoundURL: 'http://example.com/bell.mp3', // for advanced config flags please refer to https://hyperterm.org/#cfg }, diff --git a/lib/components/term.js b/lib/components/term.js index 4066ebdf..ea57b4b0 100644 --- a/lib/components/term.js +++ b/lib/components/term.js @@ -39,6 +39,12 @@ export default class Term extends Component { this.term.prefs_.set('send-encoding', 'raw'); this.term.prefs_.set('alt-sends-what', 'browser-key'); + if (props.bell === 'SOUND') { + this.term.prefs_.set('audible-bell-sound', this.props.bellSoundURL); + } else { + this.term.prefs_.set('audible-bell-sound', ''); + } + this.term.onTerminalReady = () => { const io = this.term.io.push(); io.onVTKeystroke = io.sendString = props.onData; @@ -200,6 +206,12 @@ export default class Term extends Component { if (this.props.customCSS !== nextProps.customCSS) { this.term.prefs_.set('user-css', this.getStylesheet(nextProps.customCSS)); } + + if (this.props.bell === 'SOUND') { + this.term.prefs_.set('audible-bell-sound', this.props.bellSoundURL); + } else { + this.term.prefs_.set('audible-bell-sound', ''); + } } componentWillUnmount () { diff --git a/lib/components/terms.js b/lib/components/terms.js index 977b5c2c..fdbb7dca 100644 --- a/lib/components/terms.js +++ b/lib/components/terms.js @@ -143,7 +143,9 @@ export default class Terms extends Component { onResize: this.bind(this.props.onResize, null, uid), onTitle: this.bind(this.props.onTitle, null, uid), onData: this.bind(this.props.onData, null, uid), - onURLAbort: this.bind(this.props.onURLAbort, null, uid) + onURLAbort: this.bind(this.props.onURLAbort, null, uid), + bell: this.props.bell, + bellSoundURL: this.props.bellSoundURL }); return
{ diff --git a/lib/reducers/ui.js b/lib/reducers/ui.js index 0d67fac2..226f0190 100644 --- a/lib/reducers/ui.js +++ b/lib/reducers/ui.js @@ -18,7 +18,8 @@ import { import { UPDATE_AVAILABLE } from '../constants/updater'; import { values } from '../utils/object'; -const allowedCursorShapes = ['BEAM', 'BLOCK', 'UNDERLINE']; +const allowedCursorShapes = new Set(['BEAM', 'BLOCK', 'UNDERLINE']); +const allowedBells = new Set(['SOUND', false]); // TODO: populate `config-default.js` from this :) const initial = Immutable({ @@ -64,7 +65,9 @@ const initial = Immutable({ foregroundColor: '#fff', backgroundColor: '#000', updateVersion: null, - updateNotes: null + updateNotes: null, + bell: 'SOUND', + bellSoundURL: 'lib-resource:hterm/audio/bell' }); const reducer = (state = initial, action) => { @@ -96,7 +99,7 @@ const reducer = (state = initial, action) => { ret.cursorColor = config.cursorColor; } - if (allowedCursorShapes.includes(config.cursorShape)) { + if (allowedCursorShapes.has(config.cursorShape)) { ret.cursorShape = config.cursorShape; } @@ -124,6 +127,14 @@ const reducer = (state = initial, action) => { ret.termCSS = config.termCSS; } + if (allowedBells.has(config.bell)) { + ret.bell = config.bell; + } + + if (null !== config.bellSoundURL) { + ret.bellSoundURL = config.bellSoundURL || initial.bellSoundURL; + } + if (null != config.colors) { if (Array.isArray(config.colors)) { const stateColors = Array.isArray(state.colors)