nixos-configs/modules/ags/config/widgets/audio/profiles.tsx

47 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-12-07 22:08:56 -05:00
import { bind } from 'astal';
import AstalWp from 'gi://AstalWp';
import { ComboBoxText } from '../misc/subclasses';
2024-12-14 22:14:56 -05:00
export default (devices: AstalWp.Device[]) => devices
.sort((a, b) => a.description.localeCompare(b.description))
.map((device) => (
<box className="stream" vertical>
<label label={bind(device, 'description')} />
<ComboBoxText
setup={(self) => {
const profiles = (device.get_profiles() ?? []).sort((a, b) => {
if (a.description === 'Off') {
return 1;
}
else if (b.description === 'Off') {
return -1;
}
else {
return a.description.localeCompare(b.description);
}
});
profiles.forEach((profile) => {
self.append(profile.index.toString(), profile.description);
});
self.set_active(
profiles.indexOf(
device.get_profile(device.get_active_profile())!,
),
);
}}
onChanged={(self) => {
device.set_active_profile(parseInt(self.activeId));
}}
/>
</box>
));