💄 style(ags/control-center/pages/Bluetooth): code style stuff

This commit is contained in:
retrozinndev
2025-05-25 08:55:13 -03:00
parent 0ebf32f07a
commit 58797ff01c
+11 -18
View File
@@ -23,15 +23,16 @@ export const BluetoothPage: (() => Page) = () => new Page({
: tr("control_center.pages.bluetooth.stop_discovering")), : tr("control_center.pages.bluetooth.stop_discovering")),
onClick: () => { onClick: () => {
if(AstalBluetooth.get_default().adapter.discovering) { if(AstalBluetooth.get_default().adapter.discovering) {
stopBluetoothDevicesWatch(); AstalBluetooth.get_default().adapter.stop_discovery();
return; return;
} }
watchNewDevices(); AstalBluetooth.get_default().adapter.start_discovery();
} }
} as Widget.ButtonProps) } as Widget.ButtonProps)
], ],
onClose: () => stopBluetoothDevicesWatch(), onClose: () => AstalBluetooth.get_default().adapter.discovering &&
AstalBluetooth.get_default().adapter.stop_discovery(),
spacing: 2, spacing: 2,
children: [ children: [
new Widget.Box({ new Widget.Box({
@@ -63,10 +64,11 @@ export const BluetoothPage: (() => Page) = () => new Page({
new Widget.Box({ new Widget.Box({
className: "paired", className: "paired",
orientation: Gtk.Orientation.VERTICAL, orientation: Gtk.Orientation.VERTICAL,
spacing: 2,
visible: bind(AstalBluetooth.get_default(), "devices").as((devs) => visible: bind(AstalBluetooth.get_default(), "devices").as((devs) =>
devs.filter(dev => dev.paired || dev.connected).length > 0), devs.filter(dev => dev.paired || dev.connected).length > 0),
children: bind(AstalBluetooth.get_default(), "devices").as((devs: Array<AstalBluetooth.Device>) => { children: bind(AstalBluetooth.get_default(), "devices").as((devs) => {
const connectedDevices = devs.filter((dev: AstalBluetooth.Device) => dev.connected || dev.paired) const connectedDevices = devs.filter((dev) => dev.connected || dev.paired)
return [ return [
new Widget.Label({ new Widget.Label({
@@ -74,17 +76,18 @@ export const BluetoothPage: (() => Page) = () => new Page({
label: tr("control_center.pages.bluetooth.paired_devices"), label: tr("control_center.pages.bluetooth.paired_devices"),
xalign: 0, xalign: 0,
} as Widget.LabelProps), } as Widget.LabelProps),
...connectedDevices.map((dev: AstalBluetooth.Device) => DeviceWidget(dev)) ...connectedDevices.map((dev) => DeviceWidget(dev))
] ]
}) })
} as Widget.BoxProps), } as Widget.BoxProps),
new Widget.Box({ new Widget.Box({
className: "discovered", className: "discovered",
orientation: Gtk.Orientation.VERTICAL, orientation: Gtk.Orientation.VERTICAL,
spacing: 2,
visible: bind(AstalBluetooth.get_default(), "devices").as((devs) => visible: bind(AstalBluetooth.get_default(), "devices").as((devs) =>
devs.filter((dev) => !dev.connected && !dev.paired).length > 0), devs.filter((dev) => !dev.connected && !dev.paired).length > 0),
children: bind(AstalBluetooth.get_default(), "devices").as((devices: Array<AstalBluetooth.Device>) => { children: bind(AstalBluetooth.get_default(), "devices").as((devices) => {
const discoveredDevices = devices.filter((dev: AstalBluetooth.Device) => !dev.connected && !dev.paired); const discoveredDevices = devices.filter((dev) => !dev.connected && !dev.paired);
return [ return [
new Widget.Label({ new Widget.Label({
@@ -180,13 +183,3 @@ function DeviceWidget(dev: AstalBluetooth.Device): Gtk.Widget {
extraButtons: devActions() extraButtons: devActions()
}); });
} }
function watchNewDevices(): void {
!AstalBluetooth.get_default().adapter.discovering &&
AstalBluetooth.get_default().adapter.start_discovery();
}
export function stopBluetoothDevicesWatch(): void {
AstalBluetooth.get_default().adapter.discovering &&
AstalBluetooth.get_default().adapter.stop_discovery();
}