Skip to content

Commit

Permalink
Fix confusing behavior of mute button and volume slider in web UI (ma…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Sep 8, 2023
1 parent 33c8708 commit 91040da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/javascript/mastodon/features/audio/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ class Audio extends PureComponent {
};

toggleMute = () => {
const muted = !this.state.muted;
const muted = !(this.state.muted || this.state.volume === 0);

this.setState({ muted }, () => {
this.setState((state) => ({ muted, volume: Math.max(state.volume || 0.5, 0.05) }), () => {
if (this.gainNode) {
this.gainNode.gain.value = muted ? 0 : this.state.volume;
this.gainNode.gain.value = this.state.muted ? 0 : this.state.volume;
}
});
};
Expand Down Expand Up @@ -287,7 +287,7 @@ class Audio extends PureComponent {
const { x } = getPointerPosition(this.volume, e);

if(!isNaN(x)) {
this.setState({ volume: x }, () => {
this.setState((state) => ({ volume: x, muted: state.muted && x === 0 }), () => {
if (this.gainNode) {
this.gainNode.gain.value = this.state.muted ? 0 : x;
}
Expand Down
10 changes: 6 additions & 4 deletions app/javascript/mastodon/features/video/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ class Video extends PureComponent {
const { x } = getPointerPosition(this.volume, e);

if(!isNaN(x)) {
this.setState({ volume: x }, () => {
this.setState((state) => ({ volume: x, muted: state.muted && x === 0 }), () => {
this.video.volume = x;
this.video.muted = this.state.muted;
});
}
}, 15);
Expand Down Expand Up @@ -425,10 +426,11 @@ class Video extends PureComponent {
};

toggleMute = () => {
const muted = !this.video.muted;
const muted = !(this.video.muted || this.state.volume === 0);

this.setState({ muted }, () => {
this.video.muted = muted;
this.setState((state) => ({ muted, volume: Math.max(state.volume || 0.5, 0.05) }), () => {
this.video.volume = this.state.volume;
this.video.muted = this.state.muted;
});
};

Expand Down

0 comments on commit 91040da

Please sign in to comment.