fix term crash when bell is false

This commit is contained in:
Labhansh Agrawal 2023-07-13 11:24:31 +05:30
parent ab3d4b7e8f
commit 8003736150
5 changed files with 14 additions and 8 deletions

View file

@ -33,7 +33,10 @@
}, },
"bell": { "bell": {
"description": "Supported Options:\n1. 'SOUND' -> Enables the bell as a sound\n2. false: turns off the bell", "description": "Supported Options:\n1. 'SOUND' -> Enables the bell as a sound\n2. false: turns off the bell",
"type": "string" "enum": [
"SOUND",
false
]
}, },
"bellSound": { "bellSound": {
"description": "base64 encoded string of the sound file to use for the bell\nif null, the default bell will be used", "description": "base64 encoded string of the sound file to use for the bell\nif null, the default bell will be used",
@ -357,7 +360,10 @@
}, },
"bell": { "bell": {
"description": "Supported Options:\n1. 'SOUND' -> Enables the bell as a sound\n2. false: turns off the bell", "description": "Supported Options:\n1. 'SOUND' -> Enables the bell as a sound\n2. false: turns off the bell",
"type": "string" "enum": [
"SOUND",
false
]
}, },
"bellSound": { "bellSound": {
"description": "base64 encoded string of the sound file to use for the bell\nif null, the default bell will be used", "description": "base64 encoded string of the sound file to use for the bell\nif null, the default bell will be used",

View file

@ -416,8 +416,8 @@ export default class Term extends React.PureComponent<
return !e.catched; return !e.catched;
} }
setBellSound(bell: string | null, sound: string | null) { setBellSound(bell: 'SOUND' | false, sound: string | null) {
if (bell?.toUpperCase() === 'SOUND') { if (bell && bell.toUpperCase() === 'SOUND') {
this.bellSound = sound ? new Audio(sound) : this.defaultBellSound; this.bellSound = sound ? new Audio(sound) : this.defaultBellSound;
} else { } else {
this.bellSound = null; this.bellSound = null;

2
lib/config.d.ts vendored
View file

@ -46,7 +46,7 @@ type profileConfigOptions = {
* 1. 'SOUND' -> Enables the bell as a sound * 1. 'SOUND' -> Enables the bell as a sound
* 2. false: turns off the bell * 2. false: turns off the bell
*/ */
bell: string; bell: 'SOUND' | false;
/** /**
* base64 encoded string of the sound file to use for the bell * base64 encoded string of the sound file to use for the bell
* if null, the default bell will be used * if null, the default bell will be used

4
lib/hyper.d.ts vendored
View file

@ -47,7 +47,7 @@ export type uiState = Immutable<{
activeUid: string | null; activeUid: string | null;
activityMarkers: Record<string, boolean>; activityMarkers: Record<string, boolean>;
backgroundColor: string; backgroundColor: string;
bell: string; bell: 'SOUND' | false;
bellSoundURL: string | null; bellSoundURL: string | null;
bellSound: string | null; bellSound: string | null;
borderColor: string; borderColor: string;
@ -347,7 +347,7 @@ import type {FitAddon} from 'xterm-addon-fit';
import type {SearchAddon} from 'xterm-addon-search'; import type {SearchAddon} from 'xterm-addon-search';
export type TermProps = { export type TermProps = {
backgroundColor: string; backgroundColor: string;
bell: string; bell: 'SOUND' | false;
bellSound: string | null; bellSound: string | null;
bellSoundURL: string | null; bellSoundURL: string | null;
borderColor: string; borderColor: string;

View file

@ -217,7 +217,7 @@ const reducer: IUiReducer = (state = initial, action) => {
} }
if (allowedBells.has(config.bell)) { if (allowedBells.has(config.bell)) {
ret.bell = config.bell; ret.bell = (config.bell as any) === 'false' ? false : config.bell;
} }
if (config.bellSoundURL !== state.bellSoundURL) { if (config.bellSoundURL !== state.bellSoundURL) {