nixos-configs/modules/ags/config/widgets/audio/profiles.tsx
matt1432 179e402504
All checks were successful
Discord / discord commits (push) Has been skipped
refactor(ags): prioritise getters when using astal libs
2024-12-29 17:22:55 -05:00

50 lines
1.6 KiB
TypeScript

import { bind } from 'astal';
import AstalWp from 'gi://AstalWp';
import { ComboBoxText } from '../misc/subclasses';
export default (devices: AstalWp.Device[]) => devices
.sort((a, b) => a.get_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.get_description() === 'Off') {
return 1;
}
else if (b.get_description() === 'Off') {
return -1;
}
else {
return a.get_description().localeCompare(b.get_description());
}
});
profiles.forEach((profile) => {
self.append(profile.get_index().toString(), profile.get_description());
});
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));
}
}}
/>
</box>
));