Skip to content

Commit

Permalink
Fix #198
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrews54757 committed Aug 3, 2024
1 parent ce2d02a commit df641a6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion chrome/player/ui/VolumeControls.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {EventEmitter} from '../modules/eventemitter.mjs';
import {EnvUtils} from '../utils/EnvUtils.mjs';
import {Utils} from '../utils/Utils.mjs';
import {WebUtils} from '../utils/WebUtils.mjs';
import {DOMElements} from './DOMElements.mjs';
Expand Down Expand Up @@ -29,7 +30,11 @@ export class VolumeControls extends EventEmitter {
});

DOMElements.volumeBlock.addEventListener('wheel', (e) => {
this.setVolume(Math.max(0, Math.min(3, this.client.volume + Utils.clamp(e.deltaY, -1, 1) * 0.01)));
let delta = e.deltaY;
if (!EnvUtils.isMacOS()) {
delta = -delta;
}
this.setVolume(Math.max(0, Math.min(3, this.client.volume + Utils.clamp(delta, -1, 1) * 0.01)));
e.preventDefault();
e.stopPropagation();
});
Expand Down
6 changes: 5 additions & 1 deletion chrome/player/ui/audio/AudioChannelMixer.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Localize} from '../../modules/Localize.mjs';
import {AudioUtils} from '../../utils/AudioUtils.mjs';
import {EnvUtils} from '../../utils/EnvUtils.mjs';
import {Utils} from '../../utils/Utils.mjs';
import {WebUtils} from '../../utils/WebUtils.mjs';
import {AudioChannelControl} from './config/AudioChannelControl.mjs';
Expand Down Expand Up @@ -252,7 +253,10 @@ export class AudioChannelMixer {
if (e.deltaX !== 0) return; // ignore horizontal scrolling (for trackpad)
e.preventDefault();
e.stopPropagation();
const delta = Utils.clamp(e.deltaY, -1, 1);
let delta = Utils.clamp(e.deltaY, -1, 1);
if (!EnvUtils.isMacOS()) {
delta = -delta;
}
const ratio = parseFloat(els.volumeHandle.style.top) / 100;
const db = AudioUtils.mixerPositionRatioToDB(ratio - delta * 0.05);
els.volumeHandle.style.top = `${AudioUtils.mixerDBToPositionRatio(db) * 100}%`;
Expand Down
4 changes: 4 additions & 0 deletions chrome/player/utils/EnvUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ export class EnvUtils {
static isIncognito() {
return this.isExtension() ? chrome.extension.inIncognitoContext : false;
}

static isMacOS() {
return navigator.userAgent.indexOf('Mac OS') !== -1;
}
}

0 comments on commit df641a6

Please sign in to comment.