feat(bluetooth): add battery indicator to devices with battery status
This commit is contained in:
parent
e51ca81f7d
commit
8973374a80
2 changed files with 30 additions and 2 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
// Copyright 2023 System76 <info@system76.com>
|
// Copyright 2023 System76 <info@system76.com>
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use crate::bluetooth::{BluerDeviceStatus, BluerRequest, BluerState};
|
use crate::bluetooth::{BluerDeviceStatus, BluerRequest, BluerState, DeviceProperty};
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
applet::token::subscription::{activation_token_subscription, TokenRequest, TokenUpdate},
|
applet::token::subscription::{activation_token_subscription, TokenRequest, TokenUpdate},
|
||||||
cctk::sctk::reexports::calloop,
|
cctk::sctk::reexports::calloop,
|
||||||
|
widget::text::body,
|
||||||
};
|
};
|
||||||
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
|
|
@ -367,6 +368,31 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.spacing(12);
|
.spacing(12);
|
||||||
|
|
||||||
|
if let Some(DeviceProperty::BatteryPercentage(battery)) = dev
|
||||||
|
.properties
|
||||||
|
.iter()
|
||||||
|
.find(|p| matches!(p, DeviceProperty::BatteryPercentage(_)))
|
||||||
|
{
|
||||||
|
let icon = match *battery {
|
||||||
|
b if b >= 20 && b < 40 => "battery-low",
|
||||||
|
b if b < 20 => "battery-caution",
|
||||||
|
_ => "battery",
|
||||||
|
};
|
||||||
|
let status = row!(
|
||||||
|
icon::from_name(icon).symbolic(true).size(14),
|
||||||
|
body(format!("{}%", battery))
|
||||||
|
)
|
||||||
|
.align_items(Alignment::Center)
|
||||||
|
.spacing(2)
|
||||||
|
.width(Length::Shrink);
|
||||||
|
|
||||||
|
let content = container(status)
|
||||||
|
.align_x(Horizontal::Right)
|
||||||
|
.align_y(Vertical::Center);
|
||||||
|
|
||||||
|
row = row.push(content);
|
||||||
|
}
|
||||||
|
|
||||||
match &dev.status {
|
match &dev.status {
|
||||||
BluerDeviceStatus::Connected => {
|
BluerDeviceStatus::Connected => {
|
||||||
row = row.push(
|
row = row.push(
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,12 @@
|
||||||
|
|
||||||
use std::{collections::HashMap, fmt::Debug, hash::Hash, mem, sync::Arc, time::Duration};
|
use std::{collections::HashMap, fmt::Debug, hash::Hash, mem, sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
pub use bluer::DeviceProperty;
|
||||||
use bluer::{
|
use bluer::{
|
||||||
agent::{Agent, AgentHandle},
|
agent::{Agent, AgentHandle},
|
||||||
Adapter, Address, DeviceProperty, Session, Uuid,
|
Adapter, Address, Session, Uuid,
|
||||||
};
|
};
|
||||||
|
|
||||||
use cosmic::iced::{
|
use cosmic::iced::{
|
||||||
self,
|
self,
|
||||||
futures::{SinkExt, StreamExt},
|
futures::{SinkExt, StreamExt},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue