feat: show battery on bluetooth device list (#352)

* feat: show battery on bluetooth device list

* feat: show battery on bluetooth device list

* fix: handle case when battery is not defined

* fix: handle case when battery is not defined

* feat: add bluetooth menu

* feat: add bluetooth menu

* fix: separate icon and percentage

* fix: group battery stuffs

* Update options.ts

* Update modules/menus/bluetooth/devices/devicelist.ts

* Update modules/menus/bluetooth/devices/devicelist.ts

* Update modules/menus/bluetooth/devices/devicelist.ts

---------

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
This commit is contained in:
Rubin Bhandari
2024-10-30 09:44:45 +05:45
committed by GitHub
parent a64fd64ac0
commit 0bdaf461f6
5 changed files with 93 additions and 3 deletions

View File

@@ -4,6 +4,9 @@ import { connectedControls } from './connectedControls.js';
import { getBluetoothIcon } from '../utils.js';
import Gtk from 'types/@girs/gtk-3.0/gtk-3.0.js';
import { Attribute, Child } from 'lib/types/widget.js';
import options from 'options';
const { showBattery, batteryIcon } = options.menus.bluetooth;
const devices = (bluetooth: Bluetooth, self: Box<Gtk.Widget, unknown>): Box<Child, Attribute> => {
return self.hook(bluetooth, () => {
@@ -101,10 +104,57 @@ const devices = (bluetooth: Bluetooth, self: Box<Gtk.Widget, unknown>): Box<Chil
Widget.Revealer({
hpack: 'start',
reveal_child: device.connected || device.paired,
child: Widget.Label({
child: Widget.Box({
hpack: 'start',
class_name: 'connection-status dim',
label: device.connected ? 'Connected' : 'Paired',
children: Utils.merge(
[showBattery.bind('value'), batteryIcon.bind('value')],
(showBat, batIcon) => {
if (!showBat) {
return [
Widget.Label({
hpack: 'start',
class_name: 'connection-status dim',
label: device.connected
? 'Connected'
: 'Paired',
}),
];
}
return [
Widget.Label({
hpack: 'start',
class_name: 'connection-status dim',
label: device.connected
? 'Connected'
: 'Paired',
}),
Widget.Box({
children:
typeof device.battery_percentage ===
'number' &&
device.battery_percentage >= 0
? [
Widget.Separator({
class_name:
'menu-separator',
}),
Widget.Label({
class_name:
'connection-status txt-icon',
label: `${batIcon}`,
}),
Widget.Label({
class_name:
'connection-status battery',
label: `${device.battery_percentage}%`,
}),
]
: [],
}),
];
},
),
}),
}),
],