nixos-configs/devices/wim/config/ags/js/bar/buttons/audio.js

41 lines
1 KiB
JavaScript
Raw Normal View History

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-11-16 00:48:50 -05:00
import { SpeakerIcon } from '../../misc/audio-icons.js';
import Separator from '../../misc/separator.js';
import EventBox from '../../misc/cursorbox.js';
2023-09-08 16:00:38 -04:00
const SpeakerIndicator = (props) => Icon({
...props,
binds: [['icon', SpeakerIcon, 'value']],
2023-09-08 15:23:52 -04:00
});
const SpeakerPercentLabel = (props) => Label({
...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
});
const SPACING = 5;
export default () => EventBox({
className: 'toggle-off',
onPrimaryClickRelease: () => execAsync(['pavucontrol']).catch(print),
child: Box({
className: 'audio',
children: [
SpeakerIndicator(),
Separator(SPACING),
SpeakerPercentLabel(),
],
}),
2023-09-08 15:23:52 -04:00
});