2023-09-08 15:23:52 -04:00
|
|
|
const { Audio } = ags.Service;
|
|
|
|
const { Label, Box, Icon, Stack, Button, Slider } = ags.Widget;
|
2023-09-08 16:00:38 -04:00
|
|
|
import { Separator, EventBox } from '../common.js';
|
|
|
|
|
|
|
|
const items = {
|
|
|
|
101: 'audio-volume-overamplified-symbolic',
|
|
|
|
67: 'audio-volume-high-symbolic',
|
|
|
|
34: 'audio-volume-medium-symbolic',
|
|
|
|
1: 'audio-volume-low-symbolic',
|
|
|
|
0: 'audio-volume-muted-symbolic',
|
2023-09-08 15:23:52 -04:00
|
|
|
};
|
|
|
|
|
2023-09-08 16:00:38 -04:00
|
|
|
const SpeakerIndicator = props => Icon({
|
|
|
|
...props,
|
|
|
|
icon: '',
|
|
|
|
connections: [[Audio, icon => {
|
|
|
|
if (!Audio.speaker)
|
|
|
|
return;
|
2023-09-08 15:23:52 -04:00
|
|
|
|
2023-09-08 16:00:38 -04:00
|
|
|
if (Audio.speaker.isMuted)
|
|
|
|
return icon.icon = items[0];
|
2023-09-08 15:23:52 -04:00
|
|
|
|
2023-09-08 16:00:38 -04:00
|
|
|
const vol = Audio.speaker.volume * 100;
|
|
|
|
for (const threshold of [100, 66, 33, 0, -1]) {
|
|
|
|
if (vol > threshold + 1)
|
|
|
|
return icon.icon = items[threshold + 1];
|
|
|
|
}
|
|
|
|
}, 'speaker-changed']],
|
2023-09-08 15:23:52 -04:00
|
|
|
});
|
|
|
|
|
2023-09-08 16:00:38 -04:00
|
|
|
const SpeakerPercentLabel = props => Label({
|
|
|
|
...props,
|
|
|
|
connections: [[Audio, label => {
|
|
|
|
if (!Audio.speaker)
|
|
|
|
return;
|
2023-09-08 15:23:52 -04:00
|
|
|
|
2023-09-09 13:45:14 -04:00
|
|
|
let vol = Math.floor(Audio.speaker.volume * 100);
|
|
|
|
|
|
|
|
if (vol == 0) {
|
|
|
|
label.label = vol + '%';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
label.label = vol + 1 + '%';
|
|
|
|
}
|
2023-09-08 16:00:38 -04:00
|
|
|
}, 'speaker-changed']],
|
2023-09-08 15:23:52 -04:00
|
|
|
});
|
|
|
|
|
2023-09-08 16:00:38 -04:00
|
|
|
const AudioModule = () => EventBox({
|
|
|
|
onPrimaryClickRelease: 'pavucontrol',
|
|
|
|
className: 'toggle-off',
|
|
|
|
child: Box({
|
|
|
|
className: 'audio',
|
|
|
|
children: [
|
|
|
|
SpeakerIndicator(),
|
|
|
|
Separator(5),
|
|
|
|
SpeakerPercentLabel(),
|
|
|
|
],
|
|
|
|
}),
|
2023-09-08 15:23:52 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export const AudioIndicator = AudioModule();
|