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

51 lines
1.6 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.get_description().localeCompare(b.description))
2024-12-14 22:14:56 -05:00
.map((device) => (
<box className="stream" vertical>
<label label={bind(device, 'description')} />
<ComboBoxText
setup={(self) => {
const profiles = (device.get_profiles() ?? []).sort((a, b) => {
if (a.get_description() === 'Off') {
2024-12-14 22:14:56 -05:00
return 1;
}
else if (b.get_description() === 'Off') {
2024-12-14 22:14:56 -05:00
return -1;
}
else {
return a.get_description().localeCompare(b.get_description());
2024-12-14 22:14:56 -05:00
}
});
profiles.forEach((profile) => {
self.append(profile.get_index().toString(), profile.get_description());
2024-12-14 22:14:56 -05:00
});
self.set_active(
profiles.indexOf(
device.get_profile(device.get_active_profile())!,
),
);
}}
onChanged={(self) => {
const activeId = self.get_active_id();
if (activeId) {
device.set_active_profile(parseInt(activeId));
}
2024-12-14 22:14:56 -05:00
}}
/>
</box>
));