osd: volume: show device

This commit is contained in:
end-4 2024-03-03 15:55:51 +07:00
parent 0f556381b4
commit 4de1b711ea

View file

@ -6,18 +6,18 @@ import { MarginRevealer } from '../.widgethacks/advancedrevealers.js';
import Brightness from '../../services/brightness.js';
import Indicator from '../../services/indicator.js';
const OsdValue = (name, labelSetup, progressSetup, props = {}) => {
const OsdValue = ({ name, nameSetup = undefined, labelSetup, progressSetup, ...rest }) => {
const valueName = Label({
xalign: 0, yalign: 0, hexpand: true,
className: 'osd-label',
label: `${name}`,
setup: nameSetup,
});
const valueNumber = Label({
hexpand: false, className: 'osd-value-txt',
setup: labelSetup,
});
return Box({ // Volume
...props,
vertical: true,
hexpand: true,
className: 'osd-bg osd-value',
@ -41,29 +41,48 @@ const OsdValue = (name, labelSetup, progressSetup, props = {}) => {
setup: progressSetup,
})
],
...rest,
});
}
export default () => {
const brightnessIndicator = OsdValue('Brightness',
(self) => self.hook(Brightness, self => {
const brightnessIndicator = OsdValue({
name: 'Brightness',
labelSetup: (self) => self.hook(Brightness, self => {
self.label = `${Math.round(Brightness.screen_value * 100)}`;
}, 'notify::screen-value'),
(self) => self.hook(Brightness, (progress) => {
progressSetup: (self) => self.hook(Brightness, (progress) => {
const updateValue = Brightness.screen_value;
progress.value = updateValue;
}, 'notify::screen-value'),
)
});
const volumeIndicator = OsdValue('Volume',
(self) => self.hook(Audio, (label) => {
const volumeIndicator = OsdValue({
name: 'Volume',
attribute: {
headphones: undefined,
},
nameSetup: (self) => Utils.timeout(1, () => {
const updateAudioDevice = (self) => {
const usingHeadphones = (Audio.speaker?.stream?.port)?.includes('Headphones');
if (volumeIndicator.attribute.headphones === undefined ||
volumeIndicator.attribute.headphones !== usingHeadphones) {
volumeIndicator.attribute.headphones = usingHeadphones;
self.label = usingHeadphones ? 'Headphones' : 'Speakers';
Indicator.popup(1);
}
}
self.hook(Audio, updateAudioDevice);
Utils.timeout(1000, updateAudioDevice);
}),
labelSetup: (self) => self.hook(Audio, (label) => {
label.label = `${Math.round(Audio.speaker?.volume * 100)}`;
}),
(self) => self.hook(Audio, (progress) => {
progressSetup: (self) => self.hook(Audio, (progress) => {
const updateValue = Audio.speaker?.volume;
if (!isNaN(updateValue)) progress.value = updateValue;
}),
);
});
return MarginRevealer({
transition: 'slide_down',
showClass: 'osd-show',