2023-10-02 12:06:35 -04:00
|
|
|
import { Audio, Widget } from '../../imports.js';
|
|
|
|
const { Label, Box, Icon } = Widget;
|
2023-09-11 19:57:21 -04:00
|
|
|
|
|
|
|
import { Separator } from '../misc/separator.js';
|
|
|
|
import { EventBox } from '../misc/cursorbox.js';
|
2023-09-08 16:00:38 -04:00
|
|
|
|
|
|
|
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-10-02 12:06:35 -04:00
|
|
|
|
2023-09-10 23:24:58 -04:00
|
|
|
const SpeakerIndicator = params => Icon({
|
|
|
|
...params,
|
2023-09-08 16:00:38 -04:00
|
|
|
icon: '',
|
|
|
|
connections: [[Audio, icon => {
|
2023-09-11 19:35:25 -04:00
|
|
|
if (Audio.speaker) {
|
2023-10-02 12:06:35 -04:00
|
|
|
if (Audio.speaker.stream.isMuted) {
|
2023-09-11 19:35:25 -04:00
|
|
|
icon.icon = items[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const vol = Audio.speaker.volume * 100;
|
2023-09-12 14:06:12 -04:00
|
|
|
for (const threshold of [-1, 0, 33, 66, 100]) {
|
|
|
|
if (vol > threshold + 1) {
|
2023-09-11 19:35:25 -04:00
|
|
|
icon.icon = items[threshold + 1];
|
2023-09-12 14:06:12 -04:00
|
|
|
}
|
2023-09-11 19:35:25 -04:00
|
|
|
}
|
|
|
|
}
|
2023-09-08 16:00:38 -04:00
|
|
|
}
|
|
|
|
}, 'speaker-changed']],
|
2023-09-08 15:23:52 -04:00
|
|
|
});
|
|
|
|
|
2023-09-10 23:24:58 -04:00
|
|
|
const SpeakerPercentLabel = params => Label({
|
|
|
|
...params,
|
2023-09-08 16:00:38 -04:00
|
|
|
connections: [[Audio, label => {
|
2023-09-13 01:11:11 -04:00
|
|
|
if (Audio.speaker) {
|
|
|
|
label.label = Math.round(Audio.speaker.volume * 100) + '%';
|
2023-09-09 13:45:14 -04:00
|
|
|
}
|
2023-09-08 16:00:38 -04:00
|
|
|
}, 'speaker-changed']],
|
2023-09-08 15:23:52 -04:00
|
|
|
});
|
|
|
|
|
2023-09-10 23:24:58 -04:00
|
|
|
export const AudioIndicator = EventBox({
|
2023-09-08 16:00:38 -04:00
|
|
|
onPrimaryClickRelease: 'pavucontrol',
|
|
|
|
className: 'toggle-off',
|
|
|
|
child: Box({
|
|
|
|
className: 'audio',
|
|
|
|
children: [
|
|
|
|
SpeakerIndicator(),
|
|
|
|
Separator(5),
|
|
|
|
SpeakerPercentLabel(),
|
|
|
|
],
|
|
|
|
}),
|
2023-09-08 15:23:52 -04:00
|
|
|
});
|