fix: add scrollbar with enough devices and display address for unnamed devices
This commit is contained in:
parent
f272037bdd
commit
5c725dd7a1
2 changed files with 18 additions and 6 deletions
|
|
@ -420,7 +420,8 @@ impl Application for CosmicBluetoothApplet {
|
||||||
.style(button_style.clone())
|
.style(button_style.clone())
|
||||||
.on_press(Message::ToggleVisibleDevices(!self.show_visible_devices));
|
.on_press(Message::ToggleVisibleDevices(!self.show_visible_devices));
|
||||||
content = content.push(available_connections_btn);
|
content = content.push(available_connections_btn);
|
||||||
let mut list_column = Vec::with_capacity(self.bluer_state.devices.len());
|
let mut list_column: Vec<Element<'_, Message>> =
|
||||||
|
Vec::with_capacity(self.bluer_state.devices.len());
|
||||||
|
|
||||||
if let Some((device, pin, _)) = self.request_confirmation.as_ref() {
|
if let Some((device, pin, _)) = self.request_confirmation.as_ref() {
|
||||||
let row = column![
|
let row = column![
|
||||||
|
|
@ -477,6 +478,7 @@ impl Application for CosmicBluetoothApplet {
|
||||||
.spacing(12);
|
.spacing(12);
|
||||||
list_column.push(row.into());
|
list_column.push(row.into());
|
||||||
}
|
}
|
||||||
|
let mut visible_devices_count = 0;
|
||||||
if self.show_visible_devices {
|
if self.show_visible_devices {
|
||||||
if self.bluer_state.bluetooth_enabled {
|
if self.bluer_state.bluetooth_enabled {
|
||||||
let mut visible_devices = column![];
|
let mut visible_devices = column![];
|
||||||
|
|
@ -498,7 +500,6 @@ impl Application for CosmicBluetoothApplet {
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.spacing(12);
|
.spacing(12);
|
||||||
|
|
||||||
visible_devices = visible_devices.push(
|
visible_devices = visible_devices.push(
|
||||||
button(APPLET_BUTTON_THEME)
|
button(APPLET_BUTTON_THEME)
|
||||||
.custom(vec![row.width(Length::Fill).into()])
|
.custom(vec![row.width(Length::Fill).into()])
|
||||||
|
|
@ -507,12 +508,20 @@ impl Application for CosmicBluetoothApplet {
|
||||||
)))
|
)))
|
||||||
.width(Length::Fill),
|
.width(Length::Fill),
|
||||||
);
|
);
|
||||||
|
visible_devices_count += 1;
|
||||||
}
|
}
|
||||||
list_column.push(visible_devices.into());
|
list_column.push(visible_devices.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let num_dev = list_column.len();
|
let item_counter = visible_devices_count
|
||||||
if num_dev > 5 {
|
// request confirmation is pretty big
|
||||||
|
+ if self.request_confirmation.is_some() {
|
||||||
|
5
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
if item_counter > 10 {
|
||||||
content = content.push(
|
content = content.push(
|
||||||
scrollable(Column::with_children(list_column)).height(Length::Units(300)),
|
scrollable(Column::with_children(list_column)).height(Length::Units(300)),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -183,11 +183,14 @@ impl PartialEq for BluerDevice {
|
||||||
|
|
||||||
impl BluerDevice {
|
impl BluerDevice {
|
||||||
pub async fn from_device(device: &bluer::Device) -> Self {
|
pub async fn from_device(device: &bluer::Device) -> Self {
|
||||||
let name = device
|
let mut name = device
|
||||||
.name()
|
.name()
|
||||||
.await
|
.await
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.unwrap_or_else(|| "Unknown".to_string());
|
.unwrap_or_else(|| device.address().to_string());
|
||||||
|
if name == "" {
|
||||||
|
name = device.address().to_string();
|
||||||
|
};
|
||||||
let is_paired = device.is_paired().await.unwrap_or_default();
|
let is_paired = device.is_paired().await.unwrap_or_default();
|
||||||
let is_connected = device.is_connected().await.unwrap_or_default();
|
let is_connected = device.is_connected().await.unwrap_or_default();
|
||||||
let properties = device.all_properties().await.unwrap_or_default();
|
let properties = device.all_properties().await.unwrap_or_default();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue