mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 23:57:19 +02:00
Add shortcut to mute/unmute sound
This commit is contained in:
parent
78d74cfd23
commit
9fec033173
@ -95,12 +95,16 @@ export class ControllerShortcut {
|
|||||||
StreamUiShortcut.showHideStreamMenu();
|
StreamUiShortcut.showHideStreamMenu();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ShortcutAction.STREAM_SOUND_TOGGLE:
|
||||||
|
SoundShortcut.muteUnmute();
|
||||||
|
break;
|
||||||
|
|
||||||
case ShortcutAction.STREAM_VOLUME_INC:
|
case ShortcutAction.STREAM_VOLUME_INC:
|
||||||
SoundShortcut.increaseGainNodeVolume(10);
|
SoundShortcut.adjustGainNodeVolume(10);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ShortcutAction.STREAM_VOLUME_DEC:
|
case ShortcutAction.STREAM_VOLUME_DEC:
|
||||||
SoundShortcut.decreaseGainNodeVolume(10);
|
SoundShortcut.adjustGainNodeVolume(-10);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,7 +245,7 @@ export class ControllerShortcut {
|
|||||||
[ShortcutAction.STREAM_STATS_TOGGLE]: [t('stream'), t('stats'), t('show-hide')],
|
[ShortcutAction.STREAM_STATS_TOGGLE]: [t('stream'), t('stats'), t('show-hide')],
|
||||||
[ShortcutAction.STREAM_MICROPHONE_TOGGLE]: [t('stream'), t('microphone'), t('toggle')],
|
[ShortcutAction.STREAM_MICROPHONE_TOGGLE]: [t('stream'), t('microphone'), t('toggle')],
|
||||||
[ShortcutAction.STREAM_MENU_TOGGLE]: [t('stream'), t('menu'), t('show')],
|
[ShortcutAction.STREAM_MENU_TOGGLE]: [t('stream'), t('menu'), t('show')],
|
||||||
// [ShortcutAction.STREAM_SOUND_TOGGLE]: [t('stream'), t('sound'), t('toggle')],
|
[ShortcutAction.STREAM_SOUND_TOGGLE]: [t('stream'), t('sound'), t('toggle')],
|
||||||
[ShortcutAction.STREAM_VOLUME_INC]: getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && [t('stream'), t('volume'), t('increase')],
|
[ShortcutAction.STREAM_VOLUME_INC]: getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && [t('stream'), t('volume'), t('increase')],
|
||||||
[ShortcutAction.STREAM_VOLUME_DEC]: getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && [t('stream'), t('volume'), t('decrease')],
|
[ShortcutAction.STREAM_VOLUME_DEC]: getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && [t('stream'), t('volume'), t('decrease')],
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,7 @@ import { BxEvent } from "@/utils/bx-event";
|
|||||||
import { ceilToNearest, floorToNearest } from "@/utils/utils";
|
import { ceilToNearest, floorToNearest } from "@/utils/utils";
|
||||||
|
|
||||||
export class SoundShortcut {
|
export class SoundShortcut {
|
||||||
static increaseGainNodeVolume(amount: number) {
|
static adjustGainNodeVolume(amount: number): number {
|
||||||
SoundShortcut.#adjustGainNodeVolume(amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
static decreaseGainNodeVolume(amount: number) {
|
|
||||||
SoundShortcut.#adjustGainNodeVolume(-1 * Math.abs(amount));
|
|
||||||
}
|
|
||||||
|
|
||||||
static #adjustGainNodeVolume(amount: number): number {
|
|
||||||
if (!getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL)) {
|
if (!getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -50,4 +42,49 @@ export class SoundShortcut {
|
|||||||
static setGainNodeVolume(value: number) {
|
static setGainNodeVolume(value: number) {
|
||||||
STATES.currentStream.audioGainNode && (STATES.currentStream.audioGainNode.gain.value = value / 100);
|
STATES.currentStream.audioGainNode && (STATES.currentStream.audioGainNode.gain.value = value / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static muteUnmute() {
|
||||||
|
if (getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && STATES.currentStream.audioGainNode) {
|
||||||
|
const gainValue = STATES.currentStream.audioGainNode.gain.value;
|
||||||
|
const settingValue = getPref(PrefKey.AUDIO_VOLUME);
|
||||||
|
|
||||||
|
let targetValue: number;
|
||||||
|
if (settingValue === 0) { // settingValue is 0 => set to 100
|
||||||
|
targetValue = 100;
|
||||||
|
setPref(PrefKey.AUDIO_VOLUME, targetValue);
|
||||||
|
BxEvent.dispatch(window, BxEvent.GAINNODE_VOLUME_CHANGED, {
|
||||||
|
volume: targetValue,
|
||||||
|
});
|
||||||
|
} else if (gainValue === 0) { // is being muted => set to settingValue
|
||||||
|
targetValue = settingValue;
|
||||||
|
} else { // not being muted => mute
|
||||||
|
targetValue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let status: string;
|
||||||
|
if (targetValue === 0) {
|
||||||
|
status = t('muted');
|
||||||
|
} else {
|
||||||
|
status = targetValue + '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundShortcut.setGainNodeVolume(targetValue);
|
||||||
|
Toast.show(`${t('stream')} ❯ ${t('volume')}`, status, {instant: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let $media: HTMLMediaElement;
|
||||||
|
|
||||||
|
$media = document.querySelector('div[data-testid=media-container] audio') as HTMLAudioElement;
|
||||||
|
if (!$media) {
|
||||||
|
$media = document.querySelector('div[data-testid=media-container] video') as HTMLAudioElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($media) {
|
||||||
|
$media.muted = !$media.muted;
|
||||||
|
|
||||||
|
const status = $media.muted ? t('muted') : t('unmuted');
|
||||||
|
Toast.show(`${t('stream')} ❯ ${t('volume')}`, status, {instant: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user