2023-10-31 08:32:40 -04:00
|
|
|
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
|
|
|
|
import { Label, Box, Icon } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-11-06 18:37:23 -05:00
|
|
|
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-09-11 19:57:21 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
import Separator from '../misc/separator.js';
|
|
|
|
import EventBox from '../misc/cursorbox.js';
|
2023-09-08 16:00:38 -04:00
|
|
|
|
|
|
|
const items = {
|
2023-10-20 23:11:21 -04:00
|
|
|
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-10-17 13:47:02 -04:00
|
|
|
const SpeakerIndicator = props => Icon({
|
2023-10-20 23:11:21 -04:00
|
|
|
...props,
|
|
|
|
icon: '',
|
|
|
|
connections: [[Audio, self => {
|
|
|
|
if (!Audio.speaker)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Audio.speaker.stream.isMuted) {
|
|
|
|
self.icon = items[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const vol = Audio.speaker.volume * 100;
|
|
|
|
|
|
|
|
for (const threshold of [-1, 0, 33, 66, 100]) {
|
|
|
|
if (vol > threshold + 1)
|
|
|
|
self.icon = items[threshold + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'speaker-changed']],
|
2023-09-08 15:23:52 -04:00
|
|
|
});
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
const SpeakerPercentLabel = props => Label({
|
2023-10-20 23:11:21 -04:00
|
|
|
...props,
|
|
|
|
connections: [[Audio, label => {
|
|
|
|
if (Audio.speaker)
|
|
|
|
label.label = Math.round(Audio.speaker.volume * 100) + '%';
|
|
|
|
}, 'speaker-changed']],
|
2023-09-08 15:23:52 -04:00
|
|
|
});
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export default () => EventBox({
|
2023-11-06 18:37:23 -05:00
|
|
|
onPrimaryClickRelease: () => execAsync(['pavucontrol']).catch(print),
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'toggle-off',
|
|
|
|
child: Box({
|
|
|
|
className: 'audio',
|
|
|
|
children: [
|
|
|
|
SpeakerIndicator(),
|
|
|
|
Separator(5),
|
|
|
|
SpeakerPercentLabel(),
|
|
|
|
],
|
|
|
|
}),
|
2023-09-08 15:23:52 -04:00
|
|
|
});
|