2023-10-31 08:32:40 -04:00
|
|
|
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
|
|
|
|
import { Box, Slider, Icon, EventBox } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-09-12 15:27:39 -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-12 15:27:39 -04:00
|
|
|
};
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export default () => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'slider-box',
|
|
|
|
vertical: true,
|
2023-11-06 18:37:23 -05:00
|
|
|
hpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [
|
2023-09-12 15:27:39 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
Box({
|
|
|
|
className: 'slider',
|
2023-11-06 18:37:23 -05:00
|
|
|
vpack: 'start',
|
|
|
|
hpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [
|
|
|
|
Icon({
|
|
|
|
size: 26,
|
|
|
|
className: 'slider-label',
|
|
|
|
connections: [[Audio, icon => {
|
|
|
|
if (Audio.speaker) {
|
|
|
|
if (Audio.speaker.stream.isMuted) {
|
|
|
|
icon.icon = items[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const vol = Audio.speaker.volume * 100;
|
|
|
|
for (const threshold of [-1, 0, 33, 66, 100]) {
|
|
|
|
if (vol > threshold + 1)
|
|
|
|
icon.icon = items[threshold + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'speaker-changed']],
|
|
|
|
}),
|
2023-09-12 15:27:39 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
Slider({
|
|
|
|
connections: [[Audio, slider => {
|
|
|
|
if (Audio.speaker)
|
|
|
|
slider.value = Audio.speaker.volume;
|
|
|
|
}, 'speaker-changed']],
|
|
|
|
onChange: ({ value }) => Audio.speaker.volume = value,
|
|
|
|
max: 0.999,
|
|
|
|
draw_value: false,
|
|
|
|
}),
|
|
|
|
],
|
2023-09-12 15:27:39 -04:00
|
|
|
}),
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
Box({
|
|
|
|
className: 'slider',
|
2023-11-06 18:37:23 -05:00
|
|
|
vpack: 'start',
|
|
|
|
hpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [
|
|
|
|
Icon({
|
|
|
|
className: 'slider-label',
|
|
|
|
icon: 'display-brightness-symbolic',
|
|
|
|
}),
|
2023-09-12 15:27:39 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
EventBox({
|
|
|
|
onHover: box => box.child._canChange = false,
|
|
|
|
onHoverLost: box => box.child._canChange = true,
|
|
|
|
child: Slider({
|
|
|
|
properties: [
|
|
|
|
['canChange', true],
|
|
|
|
],
|
|
|
|
onChange: ({ value }) => {
|
2023-11-10 23:51:50 -05:00
|
|
|
Brightness.screen = value;
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2023-11-10 23:51:50 -05:00
|
|
|
connections: [[Brightness, slider => {
|
|
|
|
if (slider._canChange)
|
|
|
|
slider.value = Brightness.screen;
|
|
|
|
}, 'screen']],
|
2023-10-20 23:11:21 -04:00
|
|
|
draw_value: false,
|
|
|
|
}),
|
|
|
|
}),
|
2023-09-12 16:44:47 -04:00
|
|
|
],
|
2023-09-12 15:27:39 -04:00
|
|
|
}),
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
],
|
2023-09-12 15:27:39 -04:00
|
|
|
});
|