From 81cb30833f0825f09ddcbbcfd45ddfe4adb5b853 Mon Sep 17 00:00:00 2001 From: npezza93 Date: Sat, 19 Aug 2017 16:55:05 -0400 Subject: [PATCH 1/2] When bellSound changes, update the bellAudioElements src Fixes #904 --- src/Terminal.ts | 7 +++++++ src/Types.ts | 1 + 2 files changed, 8 insertions(+) diff --git a/src/Terminal.ts b/src/Terminal.ts index 98780f5c..1dbbbc5f 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -485,6 +485,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.viewport.syncScrollArea(); break; case 'tabStopWidth': this.setupStops(); break; + case 'bellSound': this.syncBellSound(); break; case 'bellStyle': this.preloadBellSound(); break; } } @@ -2303,6 +2304,12 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.helperContainer.removeChild(this.bellAudioElement); } } + + private syncBellSound(): void { + if (this.soundBell() && this.bellAudioElement) { + this.bellAudioElement.setAttribute('src', this.options.bellSound); + } + } } /** diff --git a/src/Types.ts b/src/Types.ts index c287030d..c1cf9e63 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -31,6 +31,7 @@ export type BooleanOption = export type StringOption = 'cursorStyle' | 'bellStyle' | + 'bellSound' | 'termName'; export type StringArrayOption = 'colors'; export type NumberOption = From f983e4eb6bc24f2a4644ecd9b1fc571510b18cc5 Mon Sep 17 00:00:00 2001 From: npezza93 Date: Sat, 19 Aug 2017 18:03:04 -0400 Subject: [PATCH 2/2] Combine preloadBellSound and syncBellSound into the same function --- src/Terminal.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Terminal.ts b/src/Terminal.ts index 1dbbbc5f..332642b1 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -485,8 +485,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.viewport.syncScrollArea(); break; case 'tabStopWidth': this.setupStops(); break; - case 'bellSound': this.syncBellSound(); break; - case 'bellStyle': this.preloadBellSound(); break; + case 'bellSound': + case 'bellStyle': this.syncBellSound(); break; } } @@ -695,7 +695,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.viewportElement.appendChild(this.viewportScrollArea); // preload audio - this.preloadBellSound(); + this.syncBellSound(); // Create the selection container. this.selectionContainer = document.createElement('div'); @@ -2294,8 +2294,10 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.options.bellStyle === 'both'; } - private preloadBellSound(): void { - if (this.soundBell()) { + private syncBellSound(): void { + if (this.soundBell() && this.bellAudioElement) { + this.bellAudioElement.setAttribute('src', this.options.bellSound); + } else if (this.soundBell()) { this.bellAudioElement = document.createElement('audio'); this.bellAudioElement.setAttribute('preload', 'auto'); this.bellAudioElement.setAttribute('src', this.options.bellSound); @@ -2304,12 +2306,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.helperContainer.removeChild(this.bellAudioElement); } } - - private syncBellSound(): void { - if (this.soundBell() && this.bellAudioElement) { - this.bellAudioElement.setAttribute('src', this.options.bellSound); - } - } } /**